Spaces:
Sleeping
Sleeping
MohammedNasser
commited on
Commit
•
e59070e
1
Parent(s):
596b0f7
Update app.py
Browse files
app.py
CHANGED
@@ -243,7 +243,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
243 |
|
244 |
chat_input = gr.Textbox(label="أدخل سؤالك هنا 💬", rtl=True, visible=False)
|
245 |
chat_output = gr.Textbox(label="الردالآلي 🤖", rtl=True, visible=False)
|
246 |
-
audio_output = gr.Audio(label="🔊",
|
247 |
with gr.Group():
|
248 |
submit_button_chat = gr.Button("إرسال", interactive=True, visible=False)
|
249 |
clear_btn = gr.Button("مسح", interactive=True, visible=False)
|
@@ -257,26 +257,27 @@ with gr.Blocks(css=custom_css) as demo:
|
|
257 |
if is_valid:
|
258 |
# Enable the upload button if the file is valid
|
259 |
value=''
|
260 |
-
return gr.update(value=value), gr.update(interactive=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
|
|
261 |
else:
|
262 |
value=f'<span style="color:{color}">{message}</span>'
|
263 |
-
return gr.update(value=value), gr.update(interactive=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
264 |
|
265 |
def process_pdf_and_enable_components(pdf):
|
266 |
# Process PDF and activate the other components
|
267 |
output_label.value='<span style="color:blue">جاري معالجة الملف...</span>'
|
268 |
message, is_valid = upload_pdf(pdf)
|
269 |
value=f'<span style="color:green">{message}</span>'
|
270 |
-
return gr.update(value=value), gr.update(visible=True), gr.update(interactive=False), gr.update(visible=True), gr.update(visible=True)
|
271 |
|
272 |
def clear_chat():
|
273 |
return "", "" #
|
274 |
|
275 |
# When the user uploads a file, validate it and then allow PDF upload
|
276 |
-
pdf_input.change(handle_file_upload, inputs=pdf_input, outputs=[output_label,submit_button_pdf, submit_button_chat, chat_output, chat_input])
|
277 |
|
278 |
# When the user presses the upload button, process the PDF and enable other components
|
279 |
-
submit_button_pdf.click(process_pdf_and_enable_components, inputs=pdf_input, outputs=[output_label, submit_button_chat, submit_button_pdf, chat_output, chat_input])
|
280 |
clear_btn.click(clear_chat, outputs=[chat_input, chat_output])
|
281 |
# Chat button connection
|
282 |
submit_button_chat.click(chat, inputs=chat_input, outputs=[chat_output, audio_output])
|
|
|
243 |
|
244 |
chat_input = gr.Textbox(label="أدخل سؤالك هنا 💬", rtl=True, visible=False)
|
245 |
chat_output = gr.Textbox(label="الردالآلي 🤖", rtl=True, visible=False)
|
246 |
+
audio_output = gr.Audio(label="🔊", visible=False)
|
247 |
with gr.Group():
|
248 |
submit_button_chat = gr.Button("إرسال", interactive=True, visible=False)
|
249 |
clear_btn = gr.Button("مسح", interactive=True, visible=False)
|
|
|
257 |
if is_valid:
|
258 |
# Enable the upload button if the file is valid
|
259 |
value=''
|
260 |
+
return gr.update(value=value), gr.update(interactive=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
261 |
+
|
262 |
else:
|
263 |
value=f'<span style="color:{color}">{message}</span>'
|
264 |
+
return gr.update(value=value), gr.update(interactive=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
265 |
|
266 |
def process_pdf_and_enable_components(pdf):
|
267 |
# Process PDF and activate the other components
|
268 |
output_label.value='<span style="color:blue">جاري معالجة الملف...</span>'
|
269 |
message, is_valid = upload_pdf(pdf)
|
270 |
value=f'<span style="color:green">{message}</span>'
|
271 |
+
return gr.update(value=value), gr.update(visible=True), gr.update(interactive=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
272 |
|
273 |
def clear_chat():
|
274 |
return "", "" #
|
275 |
|
276 |
# When the user uploads a file, validate it and then allow PDF upload
|
277 |
+
pdf_input.change(handle_file_upload, inputs=pdf_input, outputs=[output_label,submit_button_pdf, submit_button_chat, chat_output, chat_input, audio_output, clear_btn])
|
278 |
|
279 |
# When the user presses the upload button, process the PDF and enable other components
|
280 |
+
submit_button_pdf.click(process_pdf_and_enable_components, inputs=pdf_input, outputs=[output_label, submit_button_chat, submit_button_pdf, chat_output, chat_input, , audio_output, clear_btn])
|
281 |
clear_btn.click(clear_chat, outputs=[chat_input, chat_output])
|
282 |
# Chat button connection
|
283 |
submit_button_chat.click(chat, inputs=chat_input, outputs=[chat_output, audio_output])
|