-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
131 lines (111 loc) · 4.83 KB
/
app.py
File metadata and controls
131 lines (111 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import io
import sys
import os
import glob
import gradio as gr
import json
import yaml
from llm.chat import Chat
from interview_master.scenario import Scenario
from interview_master.interview_master import InterviewMaster
from frontend import frontend_update
from frontend.utils.button_functions import save_code, run_the_code, submit_code, handle_chat, update_selected_scenario
from llm.clients.gemini import Gemini
# Build the Gradio interface
with gr.Blocks() as demo:
initial_state = {
"code": "",
"code_output": "",
"chat": Chat(),
"current_task": "Your current task will appear here.",
"scenario_name": "Calculator Application",
"video": """
<video id="digital_human"
autoplay
muted
controls
style="width: 100%; height: auto; border-radius: 10px;">
<source src="http://localhost:5000/combined_feed?nocache=1" type="video/mp4">
</video>
"""
}
state = gr.State(initial_state)
# Look in the scenarios folder and get all YAML files
scenarios_path = "scenarios"
scenario_files = glob.glob(os.path.join(scenarios_path, "*.yaml"))
# Create dictionary of scenario names and their paths
scenario_names = {}
for scenario_file in scenario_files:
with open(scenario_file, "r") as f:
scenario_data = yaml.safe_load(f)
scenario_names[scenario_data["name"]] = scenario_file
gr.Markdown("# InterviewMaster")
# Left Column - Wider IDE + task display
with gr.Row():
with gr.Column(scale=2): # Left column for IDE, tasks, and buttons
# Scenario dropdown and load button
with gr.Row(equal_height=True):
scenario_dropdown = gr.Dropdown(
[scenario_name for scenario_name in scenario_names.keys()],
label="Select Scenario",
value=list(scenario_names.keys())[0],
interactive=True,
type="value",
scale=5
)
load_button = gr.Button("Load Scenario", scale=1)
# Task display
task_display = gr.Markdown(label="Task Display", value=state.value['current_task'], container=True, show_label=True)
# Code editor
code_box = gr.Code(
value=state.value["code"],
language="python",
interactive=True,
label="Code Editor",
lines=10,
max_lines=25,
)
# Buttons
with gr.Row():
save_btn = gr.Button("Save", size="small")
run_btn = gr.Button("Run", size="small")
submit_btn = gr.Button("Submit", size="small")
# Output box
output_box = gr.Code(
value=state.value["code_output"],
language="python",
label="Code Output",
lines=2
)
# Right Column - Digital Human and Chat
with gr.Column(scale=1): # Digital Human and Chatbot should be in a separate column
# Digital Human Stream
# digital_human = gr.HTML(
# value="""
# <img id="video_stream" src="http://localhost:5000/video_feed"
# style="width: 100%; height: auto; border-radius: 10px;">
# <audio id="audio_stream" autoplay muted controls style="width: 100%;">
# <source src="http://localhost:5000/audio_feed" type="audio/mp3">
# </audio>
# """,
# label="Digital Human Live Stream"
# )
digital_human = gr.HTML(
value=state.value["video"],
label="Digital Human Live Stream"
)
# Chatbot area below Digital Human
with gr.Row():
history = state.value["chat"].to_history()
chatbot = gr.Chatbot(history, type="messages", label="AI Chat Response", height=245)
# User input area
with gr.Row():
user_input = gr.Textbox(label="Message to Bot:", placeholder="Type here...", scale=4)
user_input.submit(fn=handle_chat, inputs=[user_input, state],
outputs=[code_box, output_box, task_display, chatbot, state, user_input, digital_human])
# Button click functions
save_btn.click(fn=save_code, inputs=[code_box, state], outputs=[state, code_box, output_box])
run_btn.click(fn=run_the_code, inputs=[code_box, state], outputs=[state, code_box, output_box])
submit_btn.click(fn=submit_code, inputs=[code_box, state], outputs=[code_box, output_box, task_display, chatbot, state])
load_button.click(fn=update_selected_scenario, inputs=[scenario_dropdown, state], outputs=[code_box, output_box, task_display, chatbot, state])
demo.launch()