Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
from
|
4 |
-
from transformers import
|
5 |
-
from
|
6 |
-
from langchain_core.output_parsers import StrOutputParser
|
7 |
from io import BytesIO
|
8 |
import time
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
os.environ['TOGETHER_API_KEY'] = 'your_together_api_key'
|
12 |
os.environ['PINECONE_API_KEY'] = 'your_pinecone_api_key'
|
13 |
ELEVENLABS_API_KEY = 'your_elevenlabs_api_key'
|
14 |
|
15 |
-
#
|
16 |
summary_prompt = """
|
17 |
You are an expert AI summarization model tasked with creating a comprehensive summary for 10 years old kids of the provided context. The summary should be approximately one page long and well-structured.
|
18 |
|
@@ -39,13 +40,10 @@ summary_prompt_template = ChatPromptTemplate.from_template(summary_prompt)
|
|
39 |
|
40 |
# Define the PDF extraction function
|
41 |
def extract_text_from_pdf(file):
|
42 |
-
|
43 |
-
pages = loader.load_and_split()
|
44 |
-
pc.from_documents(pages, index_name='learnverse', embedding=em)
|
45 |
-
|
46 |
text = ""
|
47 |
-
for page in pages:
|
48 |
-
text += page.
|
49 |
return text
|
50 |
|
51 |
# Define the text-to-speech function
|
@@ -115,8 +113,7 @@ def evaluate_summary(generated_summary):
|
|
115 |
# Define the main processing function
|
116 |
def process_question(file):
|
117 |
pdffile = extract_text_from_pdf(file)
|
118 |
-
|
119 |
-
summary = summary_pdf_chain.invoke(pdffile)
|
120 |
evaluation = evaluate_summary(summary)
|
121 |
audio_file = text_to_speech_stream(summary)
|
122 |
return summary, evaluation, audio_file
|
@@ -132,4 +129,3 @@ gr.Interface(
|
|
132 |
inputs=gr.File(type="file", label="Upload PDF"),
|
133 |
outputs=[gr.Textbox(label="Summary"), gr.Textbox(label="Evaluation"), gr.Audio(label="Generated Audio")]
|
134 |
).launch()
|
135 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
from PyPDF2 import PdfReader
|
4 |
+
from transformers import pipeline
|
5 |
+
from langchain.prompts import ChatPromptTemplate
|
|
|
6 |
from io import BytesIO
|
7 |
import time
|
8 |
+
import wandb
|
9 |
+
from rouge import Rouge
|
10 |
|
11 |
+
# Environment variables setup
|
12 |
os.environ['TOGETHER_API_KEY'] = 'your_together_api_key'
|
13 |
os.environ['PINECONE_API_KEY'] = 'your_pinecone_api_key'
|
14 |
ELEVENLABS_API_KEY = 'your_elevenlabs_api_key'
|
15 |
|
16 |
+
# Summarization prompt
|
17 |
summary_prompt = """
|
18 |
You are an expert AI summarization model tasked with creating a comprehensive summary for 10 years old kids of the provided context. The summary should be approximately one page long and well-structured.
|
19 |
|
|
|
40 |
|
41 |
# Define the PDF extraction function
|
42 |
def extract_text_from_pdf(file):
|
43 |
+
reader = PdfReader(file)
|
|
|
|
|
|
|
44 |
text = ""
|
45 |
+
for page in reader.pages:
|
46 |
+
text += page.extract_text()
|
47 |
return text
|
48 |
|
49 |
# Define the text-to-speech function
|
|
|
113 |
# Define the main processing function
|
114 |
def process_question(file):
|
115 |
pdffile = extract_text_from_pdf(file)
|
116 |
+
summary = summary_prompt_template.invoke({"context": pdffile})
|
|
|
117 |
evaluation = evaluate_summary(summary)
|
118 |
audio_file = text_to_speech_stream(summary)
|
119 |
return summary, evaluation, audio_file
|
|
|
129 |
inputs=gr.File(type="file", label="Upload PDF"),
|
130 |
outputs=[gr.Textbox(label="Summary"), gr.Textbox(label="Evaluation"), gr.Audio(label="Generated Audio")]
|
131 |
).launch()
|
|