Spaces:
Runtime error
Runtime error
app.pyc
Browse filesπ§ Quest AI Assistant β RAG + Voice PDF Q&A π€π€
requirements_new.txt β app.pyc
RENAMED
|
@@ -12,14 +12,13 @@ from langchain.text_splitter import CharacterTextSplitter
|
|
| 12 |
from sentence_transformers import SentenceTransformer
|
| 13 |
from langchain.vectorstores import FAISS
|
| 14 |
from langchain.chains import RetrievalQA
|
| 15 |
-
from langchain.llms import HuggingFacePipeline
|
| 16 |
from transformers import pipeline
|
| 17 |
from gtts import gTTS
|
| 18 |
from io import BytesIO
|
| 19 |
|
| 20 |
# -------- PDF Reading --------
|
| 21 |
-
def read_pdf(
|
| 22 |
-
pdf_reader = PyPDF2.PdfReader(
|
| 23 |
text = ""
|
| 24 |
for page in pdf_reader.pages:
|
| 25 |
text += page.extract_text()
|
|
@@ -47,7 +46,7 @@ def answer_question(vectorstore, query):
|
|
| 47 |
answer = text_gen(context + "\nQ: " + query + "\nA:", max_length=150)[0]["generated_text"]
|
| 48 |
return answer
|
| 49 |
|
| 50 |
-
# --------
|
| 51 |
def text_to_speech(text):
|
| 52 |
tts = gTTS(text)
|
| 53 |
audio_fp = BytesIO()
|
|
@@ -66,12 +65,10 @@ def process(pdf_file, question):
|
|
| 66 |
|
| 67 |
interface = gr.Interface(
|
| 68 |
fn=process,
|
| 69 |
-
inputs=[gr.File(label="Upload PDF"), gr.Textbox(label="Ask Question")],
|
| 70 |
outputs=[gr.Textbox(label="Answer"), gr.Audio(label="Answer in Voice")],
|
| 71 |
title="π§ Quest AI Assistant β RAG + Voice PDF Q&A π€π€",
|
| 72 |
-
description="Upload
|
| 73 |
)
|
| 74 |
|
| 75 |
interface.launch()
|
| 76 |
-
|
| 77 |
-
|
|
|
|
| 12 |
from sentence_transformers import SentenceTransformer
|
| 13 |
from langchain.vectorstores import FAISS
|
| 14 |
from langchain.chains import RetrievalQA
|
|
|
|
| 15 |
from transformers import pipeline
|
| 16 |
from gtts import gTTS
|
| 17 |
from io import BytesIO
|
| 18 |
|
| 19 |
# -------- PDF Reading --------
|
| 20 |
+
def read_pdf(file_path):
|
| 21 |
+
pdf_reader = PyPDF2.PdfReader(file_path)
|
| 22 |
text = ""
|
| 23 |
for page in pdf_reader.pages:
|
| 24 |
text += page.extract_text()
|
|
|
|
| 46 |
answer = text_gen(context + "\nQ: " + query + "\nA:", max_length=150)[0]["generated_text"]
|
| 47 |
return answer
|
| 48 |
|
| 49 |
+
# -------- Text-to-Speech --------
|
| 50 |
def text_to_speech(text):
|
| 51 |
tts = gTTS(text)
|
| 52 |
audio_fp = BytesIO()
|
|
|
|
| 65 |
|
| 66 |
interface = gr.Interface(
|
| 67 |
fn=process,
|
| 68 |
+
inputs=[gr.File(label="Upload PDF"), gr.Textbox(label="Ask a Question")],
|
| 69 |
outputs=[gr.Textbox(label="Answer"), gr.Audio(label="Answer in Voice")],
|
| 70 |
title="π§ Quest AI Assistant β RAG + Voice PDF Q&A π€π€",
|
| 71 |
+
description="Upload any PDF and ask questions. Get answers in text and voice instantly!"
|
| 72 |
)
|
| 73 |
|
| 74 |
interface.launch()
|
|
|
|
|
|