Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,8 @@ from langchain_google_genai import ChatGoogleGenerativeAI
|
|
17 |
from PyPDF2 import PdfReader
|
18 |
from gtts import gTTS
|
19 |
|
|
|
|
|
20 |
# ✅ Configure logging
|
21 |
logging.basicConfig(level=logging.INFO)
|
22 |
|
@@ -86,19 +88,10 @@ def process_documents(selected_files):
|
|
86 |
return "✅ Documents processed successfully!"
|
87 |
|
88 |
# ✅ Query document
|
89 |
-
|
90 |
-
if vector_store is None:
|
91 |
-
return "❌ No documents processed.", None
|
92 |
-
retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 5})
|
93 |
-
model = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=GOOGLE_API_KEY)
|
94 |
-
qa_chain = RetrievalQA.from_chain_type(llm=model, retriever=retriever)
|
95 |
-
response = qa_chain.invoke({"query": question})["result"]
|
96 |
-
tts = gTTS(text=response, lang="en")
|
97 |
-
temp_audio_path = os.path.join(temp_dir, "response.mp3")
|
98 |
-
tts.save(temp_audio_path)
|
99 |
-
return response, temp_audio_path
|
100 |
|
101 |
def query_document(question):
|
|
|
102 |
if vector_store is None:
|
103 |
return "❌ No documents processed.", None
|
104 |
|
|
|
17 |
from PyPDF2 import PdfReader
|
18 |
from gtts import gTTS
|
19 |
|
20 |
+
temp_file_map = {}
|
21 |
+
|
22 |
# ✅ Configure logging
|
23 |
logging.basicConfig(level=logging.INFO)
|
24 |
|
|
|
88 |
return "✅ Documents processed successfully!"
|
89 |
|
90 |
# ✅ Query document
|
91 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
def query_document(question):
|
94 |
+
|
95 |
if vector_store is None:
|
96 |
return "❌ No documents processed.", None
|
97 |
|