Spaces:
Sleeping
Sleeping
MohammedNasser
commited on
Commit
•
55a1f5b
1
Parent(s):
03ed832
Update app.py
Browse files
app.py
CHANGED
@@ -205,32 +205,49 @@ with gr.Blocks(css=custom_css) as demo:
|
|
205 |
gr.Markdown("# ديمو بوت للقاء مركز حضرموت للدراسات التاريخية")
|
206 |
gr.Markdown("## المنعقد السبت 14 - سبتمبر 2024")
|
207 |
|
|
|
208 |
with gr.Row():
|
209 |
pdf_input = gr.File(label="اختر ملف PDF للدردشة")
|
210 |
process_button = gr.Button("رفع وبدء الدردشة")
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
process_button.click(process_pdf, inputs=[pdf_input], outputs=[chat_interface.textbox])
|
227 |
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
demo.launch()
|
236 |
|
|
|
|
205 |
gr.Markdown("# ديمو بوت للقاء مركز حضرموت للدراسات التاريخية")
|
206 |
gr.Markdown("## المنعقد السبت 14 - سبتمبر 2024")
|
207 |
|
208 |
+
# File input and process button
|
209 |
with gr.Row():
|
210 |
pdf_input = gr.File(label="اختر ملف PDF للدردشة")
|
211 |
process_button = gr.Button("رفع وبدء الدردشة")
|
212 |
|
213 |
+
# Chat interface and audio output
|
214 |
+
chat_interface = gr.ChatInterface(
|
215 |
+
chat,
|
216 |
+
title="الدردشة مع البوت",
|
217 |
+
description="اسأل أي سؤال عن محتوى الملف PDF",
|
218 |
+
theme="soft",
|
219 |
+
examples=["ما هو موضوع الوثيقة؟", "من هم الأشخاص المذكورون؟", "ما هي التواريخ الرئيسية المذكورة؟"],
|
220 |
+
cache_examples=True,
|
221 |
+
retry_btn=None,
|
222 |
+
undo_btn="مسح آخر رسالة",
|
223 |
+
clear_btn="مسح المحادثة",
|
224 |
+
)
|
225 |
|
226 |
+
audio_output = gr.Audio(label="الرد الصوتي")
|
|
|
|
|
227 |
|
228 |
+
# State to store the vectorstore
|
229 |
+
vectorstore_state = gr.State()
|
230 |
+
|
231 |
+
# Ensure chat interface is disabled until PDF is processed
|
232 |
+
process_button.click(
|
233 |
+
fn=process_pdf,
|
234 |
+
inputs=[pdf_input],
|
235 |
+
outputs=[chat_interface.textbox, vectorstore_state] # Store the vectorstore in the state
|
236 |
+
)
|
237 |
+
|
238 |
+
# Enable chat only after PDF is processed and vectorstore is ready
|
239 |
+
def handle_chat(user_input, history, vectorstore):
|
240 |
+
if vectorstore is None:
|
241 |
+
return "Please upload and process a PDF first.", ""
|
242 |
+
return chat(user_input, history, vectorstore)
|
243 |
+
|
244 |
+
# Use the state to pass the vectorstore to the chat
|
245 |
+
chat_interface.submit(
|
246 |
+
fn=handle_chat,
|
247 |
+
inputs=[chat_interface.textbox, chat_interface.chatbot, vectorstore_state], # Pass the vectorstore as input
|
248 |
+
outputs=[audio_output]
|
249 |
+
)
|
250 |
|
251 |
demo.launch()
|
252 |
|
253 |
+
|