Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -530,6 +530,28 @@ def main():
|
|
530 |
)
|
531 |
|
532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
533 |
# --- Gradio callback functions ---
|
534 |
|
535 |
def start_interview():
|
@@ -600,37 +622,41 @@ def main():
|
|
600 |
# --- Wire up the event handlers ---
|
601 |
|
602 |
# 1) Start button
|
|
|
603 |
start_btn.click(
|
604 |
start_interview,
|
605 |
inputs=[],
|
606 |
-
outputs=[chatbot, user_input, audio_output]
|
607 |
)
|
608 |
|
609 |
# 2) Audio: when recording stops
|
|
|
610 |
audio_input.stop_recording(
|
611 |
interview_step_wrapper,
|
612 |
inputs=[user_input, audio_input, chatbot],
|
613 |
-
outputs=[chatbot, user_input, audio_output]
|
614 |
)
|
615 |
|
616 |
# 3) Submit button
|
|
|
617 |
submit_btn.click(
|
618 |
interview_step_wrapper,
|
619 |
inputs=[user_input, audio_input, chatbot],
|
620 |
-
outputs=[chatbot, user_input, audio_output]
|
621 |
)
|
622 |
# 4) User input textbox submits (Enter key)
|
623 |
-
user_input.submit(
|
624 |
on_enter_submit,
|
625 |
-
inputs=[chatbot, user_input],
|
626 |
-
outputs=[chatbot, user_input, audio_output]
|
627 |
)
|
628 |
|
629 |
# 5) Clear button
|
|
|
630 |
clear_btn.click(
|
631 |
clear_chat,
|
632 |
inputs=[],
|
633 |
-
outputs=[chatbot, user_input, audio_output]
|
634 |
)
|
635 |
|
636 |
|
|
|
530 |
)
|
531 |
|
532 |
|
533 |
+
# --- Chatbot, User Input, Audio Output definitions (moved to be before button event handlers) ---
|
534 |
+
chatbot = gr.Chatbot(
|
535 |
+
[],
|
536 |
+
elem_id="chatbot",
|
537 |
+
bubble_full_width=False,
|
538 |
+
height=650
|
539 |
+
)
|
540 |
+
|
541 |
+
user_input = gr.Textbox(
|
542 |
+
"",
|
543 |
+
placeholder="Type response here... or record audio",
|
544 |
+
elem_id="user-input",
|
545 |
+
show_label=False,
|
546 |
+
)
|
547 |
+
|
548 |
+
audio_output = gr.Audio(
|
549 |
+
autoplay=True,
|
550 |
+
streaming=False
|
551 |
+
)
|
552 |
+
# --- End of Chatbot, User Input, Audio Output definitions ---
|
553 |
+
|
554 |
+
|
555 |
# --- Gradio callback functions ---
|
556 |
|
557 |
def start_interview():
|
|
|
622 |
# --- Wire up the event handlers ---
|
623 |
|
624 |
# 1) Start button
|
625 |
+
start_btn = gr.Button("Start Interview", variant="primary") # Define start_btn here
|
626 |
start_btn.click(
|
627 |
start_interview,
|
628 |
inputs=[],
|
629 |
+
outputs=[chatbot, user_input, audio_output] # Now chatbot, user_input, audio_output are defined
|
630 |
)
|
631 |
|
632 |
# 2) Audio: when recording stops
|
633 |
+
audio_input = gr.Audio(sources=["microphone"], streaming=False, type="filepath", label="Record Audio") # Define audio_input here, before use
|
634 |
audio_input.stop_recording(
|
635 |
interview_step_wrapper,
|
636 |
inputs=[user_input, audio_input, chatbot],
|
637 |
+
outputs=[chatbot, user_input, audio_output] # chatbot, user_input, audio_output are defined
|
638 |
)
|
639 |
|
640 |
# 3) Submit button
|
641 |
+
submit_btn = gr.Button("Submit", variant="primary") # Define submit_btn here
|
642 |
submit_btn.click(
|
643 |
interview_step_wrapper,
|
644 |
inputs=[user_input, audio_input, chatbot],
|
645 |
+
outputs=[chatbot, user_input, audio_output] # chatbot, user_input, audio_output are defined
|
646 |
)
|
647 |
# 4) User input textbox submits (Enter key)
|
648 |
+
user_input.submit( # user_input is defined
|
649 |
on_enter_submit,
|
650 |
+
inputs=[chatbot, user_input], # chatbot, user_input are defined
|
651 |
+
outputs=[chatbot, user_input, audio_output] # chatbot, user_input, audio_output are defined
|
652 |
)
|
653 |
|
654 |
# 5) Clear button
|
655 |
+
clear_btn = gr.Button("Clear Chat") # Define clear_btn here
|
656 |
clear_btn.click(
|
657 |
clear_chat,
|
658 |
inputs=[],
|
659 |
+
outputs=[chatbot, user_input, audio_output] # chatbot, user_input, audio_output are defined
|
660 |
)
|
661 |
|
662 |
|