Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -445,9 +445,11 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
|
|
445 |
hallucination_label = evaluate_hallucination(final_response, markdown_output)
|
446 |
print("Hallucination Label:", hallucination_label) # Debug print
|
447 |
|
|
|
|
|
|
|
448 |
return final_response, hallucination_label
|
449 |
except Exception as e:
|
450 |
-
# Handle exceptions
|
451 |
print(f"An error occurred: {e}")
|
452 |
return "Error occurred during processing.", "No hallucination evaluation"
|
453 |
|
@@ -573,72 +575,44 @@ languages = [
|
|
573 |
"Standard Malay",
|
574 |
"Zulu"
|
575 |
]
|
576 |
-
def process_and_query(input_language, audio_input, image_input, text_input):
|
577 |
-
# Your processing logic here
|
578 |
-
# Hide input components and show result components after processing
|
579 |
-
components['speech_to_text'].hide()
|
580 |
-
components['image_identification'].hide()
|
581 |
-
components['text_summarization'].hide()
|
582 |
-
components['results'].show()
|
583 |
-
# Return the processed text and hallucination evaluation
|
584 |
-
return "Processed Text in " + input_language, "Hallucination Evaluation"
|
585 |
|
586 |
-
def clear():
|
587 |
-
|
588 |
-
|
589 |
-
components['image_identification'].hide()
|
590 |
-
components['text_summarization'].hide()
|
591 |
-
components['results'].hide()
|
592 |
|
593 |
-
def on_language_change(language):
|
594 |
-
if language:
|
595 |
-
components['speech_to_text'].show()
|
596 |
-
components['image_identification'].show()
|
597 |
-
components['text_summarization'].show()
|
598 |
-
else:
|
599 |
-
components['speech_to_text'].hide()
|
600 |
-
components['image_identification'].hide()
|
601 |
-
components['text_summarization'].hide()
|
602 |
|
|
|
|
|
|
|
|
|
|
|
603 |
|
604 |
-
|
|
|
|
|
|
|
605 |
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
components['text_summarization'] = text_summarization
|
627 |
-
|
628 |
-
with gr.Row() as results:
|
629 |
-
text_output = gr.Markdown()
|
630 |
-
hallucination_output = gr.Label()
|
631 |
-
components['results'] = results
|
632 |
-
|
633 |
-
clear_button = gr.Button("Clear")
|
634 |
-
clear_button.click(clear, inputs=[], outputs=[])
|
635 |
-
|
636 |
-
text_button.click(process_and_query, inputs=[input_language, audio_input, image_input, text_input], outputs=[text_output, hallucination_output])
|
637 |
-
|
638 |
-
# Initially hide all blocks except language selection
|
639 |
-
components['speech_to_text'].hide()
|
640 |
-
components['image_identification'].hide()
|
641 |
-
components['text_summarization'].hide()
|
642 |
-
components['results'].hide()
|
643 |
|
|
|
|
|
644 |
iface.launch(show_error=True, debug=True)
|
|
|
445 |
hallucination_label = evaluate_hallucination(final_response, markdown_output)
|
446 |
print("Hallucination Label:", hallucination_label) # Debug print
|
447 |
|
448 |
+
state['show_results'] = True
|
449 |
+
create_interface(state) # Recreate the interface with the updated state
|
450 |
+
|
451 |
return final_response, hallucination_label
|
452 |
except Exception as e:
|
|
|
453 |
print(f"An error occurred: {e}")
|
454 |
return "Error occurred during processing.", "No hallucination evaluation"
|
455 |
|
|
|
575 |
"Standard Malay",
|
576 |
"Zulu"
|
577 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
|
579 |
+
def clear(state):
|
580 |
+
state['show_results'] = False
|
581 |
+
create_interface(state) # Recreate the interface with the updated state
|
|
|
|
|
|
|
582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
583 |
|
584 |
+
def create_interface(state):
|
585 |
+
with gr.Blocks(theme='ParityError/Anime') as iface:
|
586 |
+
with gr.Row():
|
587 |
+
input_language = gr.Dropdown(languages, label="Select the language", value="English", interactive=True)
|
588 |
+
input_language.change(lambda x: create_interface(state))
|
589 |
|
590 |
+
if not state.get('show_results'):
|
591 |
+
with gr.Accordion("Use Voice", open=False):
|
592 |
+
audio_input = gr.Audio(label="Speak", type="filepath", sources="microphone")
|
593 |
+
audio_output = gr.Markdown(label="Output text")
|
594 |
|
595 |
+
with gr.Accordion("Use a Picture", open=False):
|
596 |
+
image_input = gr.Image(label="Upload image")
|
597 |
+
image_output = gr.Markdown(label="Output text")
|
598 |
+
|
599 |
+
with gr.Accordion("MultiMed", open=False):
|
600 |
+
text_input = gr.Textbox(label="Use Text", lines=5)
|
601 |
+
text_output = gr.Markdown(label="Output text")
|
602 |
+
text_button = gr.Button("Use MultiMed")
|
603 |
+
hallucination_output = gr.Label(label="Hallucination Evaluation")
|
604 |
+
text_button.click(process_and_query, inputs=[state, input_language, audio_input, image_input, text_input], outputs=[text_output, hallucination_output])
|
605 |
+
|
606 |
+
if state.get('show_results'):
|
607 |
+
with gr.Row():
|
608 |
+
text_output = gr.Markdown()
|
609 |
+
hallucination_output = gr.Label()
|
610 |
+
|
611 |
+
clear_button = gr.Button("Clear")
|
612 |
+
clear_button.click(clear, inputs=[state], outputs=[])
|
613 |
+
|
614 |
+
return iface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
|
616 |
+
state = {'show_results': False}
|
617 |
+
iface = create_interface(state)
|
618 |
iface.launch(show_error=True, debug=True)
|