Tonic commited on
Commit
c797359
1 Parent(s): 2465d71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -33
app.py CHANGED
@@ -444,7 +444,6 @@ def process_and_query(state, input_language=None, audio_input=None, image_input=
444
  # Evaluate hallucination
445
  hallucination_label = evaluate_hallucination(final_response, markdown_output)
446
  print("Hallucination Label:", hallucination_label) # Debug print
447
- state['show_results'] = True
448
  return final_response, hallucination_label
449
  except Exception as e:
450
  print(f"An error occurred: {e}")
@@ -573,43 +572,33 @@ languages = [
573
  "Zulu"
574
  ]
575
 
 
 
 
576
 
577
- def clear(state):
578
- state['show_results'] = False
579
- return state
580
-
581
- def create_interface(state):
582
  with gr.Blocks(theme='ParityError/Anime') as iface:
583
- with gr.Row():
584
- input_language = gr.Dropdown(languages, label="Select the language", value="English", interactive=True)
585
- input_language.change(lambda x: create_interface({'show_results': False}))
586
-
587
- if not state.get('show_results'):
588
- with gr.Accordion("Use Voice", open=False):
589
- audio_input = gr.Audio(label="Speak", type="filepath", sources="microphone")
590
- audio_output = gr.Markdown(label="Output text")
591
-
592
- with gr.Accordion("Use a Picture", open=False):
593
- image_input = gr.Image(label="Upload image")
594
- image_output = gr.Markdown(label="Output text")
595
-
596
- with gr.Accordion("MultiMed", open=False):
597
- text_input = gr.Textbox(label="Use Text", lines=5)
598
- text_output = gr.Markdown(label="Output text")
599
- text_button = gr.Button("Use MultiMed")
600
- hallucination_output = gr.Label(label="Hallucination Evaluation")
601
- text_button.click(process_and_query, inputs=[input_language, audio_input, image_input, text_input, state], outputs=[text_output, hallucination_output])
602
-
603
- if state.get('show_results'):
604
- with gr.Row():
605
- text_output = gr.Markdown()
606
- hallucination_output = gr.Label()
607
 
608
  clear_button = gr.Button("Clear")
609
- clear_button.click(clear, inputs=[state], outputs=[state])
610
 
611
  return iface
612
 
613
- state = {'show_results': False}
614
- iface = create_interface(state)
615
  iface.launch(show_error=True, debug=True)
 
444
  # Evaluate hallucination
445
  hallucination_label = evaluate_hallucination(final_response, markdown_output)
446
  print("Hallucination Label:", hallucination_label) # Debug print
 
447
  return final_response, hallucination_label
448
  except Exception as e:
449
  print(f"An error occurred: {e}")
 
572
  "Zulu"
573
  ]
574
 
575
+ def clear(input_language, audio_input, image_input, text_input):
576
+ # Reset each input to its default state
577
+ return "", None, None, "", []
578
 
579
+ def create_interface():
 
 
 
 
580
  with gr.Blocks(theme='ParityError/Anime') as iface:
581
+ input_language = gr.Dropdown(languages, label="Select the language", value="English", interactive=True)
582
+
583
+ with gr.Accordion("Use Voice", open=False) as voice_accordion:
584
+ audio_input = gr.Audio(label="Speak", type="filepath", sources="microphone")
585
+ audio_output = gr.Markdown(label="Output text")
586
+
587
+ with gr.Accordion("Use a Picture", open=False) as picture_accordion:
588
+ image_input = gr.Image(label="Upload image")
589
+ image_output = gr.Markdown(label="Output text")
590
+
591
+ with gr.Accordion("MultiMed", open=False) as multimend_accordion:
592
+ text_input = gr.Textbox(label="Use Text", lines=5)
593
+ text_output = gr.Markdown(label="Output text")
594
+ text_button = gr.Button("Use MultiMed")
595
+ hallucination_output = gr.Label(label="Hallucination Evaluation")
596
+ text_button.click(process_and_query, inputs=[input_language, audio_input, image_input, text_input], outputs=[text_output, hallucination_output])
 
 
 
 
 
 
 
 
597
 
598
  clear_button = gr.Button("Clear")
599
+ clear_button.click(clear, inputs=[], outputs=[])
600
 
601
  return iface
602
 
603
+ iface = create_interface()
 
604
  iface.launch(show_error=True, debug=True)