MohammedNasser commited on
Commit
596b0f7
·
verified ·
1 Parent(s): 3e9508c

Update app.py

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