Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -200,8 +200,8 @@ def validate_pdf(pdf):
|
|
200 |
return "الملف صالح للدردشة", True
|
201 |
|
202 |
def upload_pdf(pdf_file):
|
203 |
-
global vectorstore, chain,
|
204 |
-
|
205 |
data = load_pdf(pdf_file)
|
206 |
vectorstore = prepare_vectorstore(data)
|
207 |
chain = create_chain(vectorstore)
|
@@ -209,7 +209,7 @@ def upload_pdf(pdf_file):
|
|
209 |
|
210 |
|
211 |
def chat(user_input):
|
212 |
-
global chain
|
213 |
|
214 |
chat_history.append({"role": "user", "content": user_input})
|
215 |
|
@@ -226,7 +226,7 @@ def chat(user_input):
|
|
226 |
response = chain({"question": prompt})
|
227 |
assistant_response = response["answer"]
|
228 |
|
229 |
-
|
230 |
# Generate a unique identifier for the audio file
|
231 |
audio_id = str(uuid.uuid4())
|
232 |
|
@@ -235,7 +235,7 @@ def chat(user_input):
|
|
235 |
audio_file = f"{audio_id}.mp3"
|
236 |
tts.save(audio_file)
|
237 |
|
238 |
-
history_display = [(h["role"], h["content"]) for h in
|
239 |
return history_display, audio_file
|
240 |
|
241 |
with gr.Blocks(css=custom_css) as demo:
|
|
|
200 |
return "الملف صالح للدردشة", True
|
201 |
|
202 |
def upload_pdf(pdf_file):
|
203 |
+
global vectorstore, chain,chathistory
|
204 |
+
chathistory = []
|
205 |
data = load_pdf(pdf_file)
|
206 |
vectorstore = prepare_vectorstore(data)
|
207 |
chain = create_chain(vectorstore)
|
|
|
209 |
|
210 |
|
211 |
def chat(user_input):
|
212 |
+
global chain chathistory
|
213 |
|
214 |
chat_history.append({"role": "user", "content": user_input})
|
215 |
|
|
|
226 |
response = chain({"question": prompt})
|
227 |
assistant_response = response["answer"]
|
228 |
|
229 |
+
chathistory.append({"role": "assistant", "content": assistant_response})
|
230 |
# Generate a unique identifier for the audio file
|
231 |
audio_id = str(uuid.uuid4())
|
232 |
|
|
|
235 |
audio_file = f"{audio_id}.mp3"
|
236 |
tts.save(audio_file)
|
237 |
|
238 |
+
history_display = [(h["role"], h["content"]) for h in chathistory]
|
239 |
return history_display, audio_file
|
240 |
|
241 |
with gr.Blocks(css=custom_css) as demo:
|