Spaces:
Sleeping
Sleeping
IliaLarchenko
commited on
Commit
•
1b279d5
1
Parent(s):
f913a0b
Refactoring
Browse files- app.py +71 -72
- options.py +11 -31
app.py
CHANGED
@@ -1,7 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from llm import end_interview, get_problem, read_last_message, send_request, transcribe_audio
|
4 |
-
from options import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
def hide_settings():
|
@@ -9,72 +20,60 @@ def hide_settings():
|
|
9 |
start_btn = gr.Button("Generate a problem", interactive=False)
|
10 |
solution_acc = gr.Accordion("Solution", open=True)
|
11 |
end_btn = gr.Button("Finish the interview", interactive=True)
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
(
|
23 |
-
None,
|
24 |
-
"Welcome to the interview! Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have. Good luck!",
|
25 |
-
)
|
26 |
-
]
|
27 |
-
return init_acc, start_btn, solution_acc, end_btn, send_btn, audio_input, chat
|
28 |
|
29 |
|
30 |
def hide_solution():
|
31 |
solution_acc = gr.Accordion("Solution", open=False)
|
32 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
33 |
problem_acc = gr.Accordion("Problem statement", open=False)
|
34 |
-
|
35 |
-
|
36 |
-
label="Record audio",
|
37 |
-
sources=["microphone"],
|
38 |
-
type="numpy",
|
39 |
-
waveform_options={"show_controls": False},
|
40 |
-
interactive=False,
|
41 |
-
editable=False,
|
42 |
-
)
|
43 |
-
return solution_acc, end_btn, problem_acc, send_btn, audio_input
|
44 |
-
|
45 |
-
|
46 |
-
def return_none():
|
47 |
-
return None
|
48 |
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown("Your coding interview practice AI assistant!")
|
52 |
-
# TODO: add instructions tab
|
53 |
# TODO: add other types of interviews (e.g. system design, ML design, behavioral, etc.)
|
54 |
|
55 |
-
with gr.Tab("Coding"):
|
56 |
chat_history = gr.State([])
|
57 |
previous_code = gr.State("")
|
58 |
client = gr.State(None)
|
|
|
59 |
with gr.Accordion("Settings") as init_acc:
|
60 |
with gr.Row():
|
61 |
with gr.Column():
|
62 |
-
gr.Markdown("
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
gr.
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
start_btn = gr.Button("Generate a problem")
|
79 |
|
80 |
# TODO: select LLM model
|
@@ -83,47 +82,47 @@ with gr.Blocks() as demo:
|
|
83 |
with gr.Accordion("Solution", open=False) as solution_acc:
|
84 |
with gr.Row() as content:
|
85 |
with gr.Column(scale=2):
|
86 |
-
|
87 |
-
label="
|
88 |
)
|
89 |
-
code = gr.Code(label="Solution", language=language_select.value, lines=35)
|
90 |
with gr.Column(scale=1):
|
91 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
92 |
-
chat = gr.Chatbot(label="Chat
|
93 |
-
audio_input = gr.Audio(
|
94 |
-
label="Record audio",
|
95 |
-
sources=["microphone"],
|
96 |
-
type="numpy",
|
97 |
-
waveform_options={"show_controls": False},
|
98 |
-
interactive=False,
|
99 |
-
editable=False,
|
100 |
-
)
|
101 |
audio_output = gr.Audio(label="Play audio", autoplay=True, visible=False)
|
102 |
-
message = gr.Textbox(label="Message", lines=3)
|
103 |
-
send_btn = gr.Button("Send", interactive=False)
|
104 |
|
105 |
with gr.Accordion("Feedback", open=True) as feedback_acc:
|
106 |
feedback = gr.Markdown()
|
107 |
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
109 |
fn=get_problem,
|
110 |
inputs=[requirements, difficulty_select, topic_select, model_select],
|
111 |
outputs=[description, chat_history],
|
112 |
scroll_to_output=True,
|
113 |
-
).then(fn=hide_settings, inputs=None, outputs=[init_acc, start_btn, solution_acc, end_btn,
|
114 |
|
115 |
-
|
116 |
fn=send_request,
|
117 |
inputs=[code, previous_code, message, chat_history, chat, model_select],
|
118 |
outputs=[chat_history, chat, message, previous_code],
|
119 |
)
|
120 |
|
121 |
-
end_btn.click(
|
122 |
-
fn=
|
123 |
-
|
|
|
|
|
|
|
|
|
124 |
|
125 |
audio_input.stop_recording(fn=transcribe_audio, inputs=[audio_input], outputs=[message]).then(
|
126 |
-
fn=
|
127 |
).then(
|
128 |
fn=send_request,
|
129 |
inputs=[code, previous_code, message, chat_history, chat, model_select],
|
@@ -132,6 +131,6 @@ with gr.Blocks() as demo:
|
|
132 |
|
133 |
chat.change(fn=read_last_message, inputs=[chat], outputs=[audio_output])
|
134 |
|
135 |
-
audio_output.stop(fn=
|
136 |
|
137 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from llm import end_interview, get_problem, read_last_message, send_request, transcribe_audio
|
4 |
+
from options import fixed_messages, models, topics_list
|
5 |
+
|
6 |
+
default_audio_params = {
|
7 |
+
"label": "Record answer",
|
8 |
+
"sources": ["microphone"],
|
9 |
+
"type": "numpy",
|
10 |
+
"waveform_options": {"show_controls": False},
|
11 |
+
"editable": False,
|
12 |
+
"container": False,
|
13 |
+
"show_share_button": False,
|
14 |
+
"min_length": 5,
|
15 |
+
}
|
16 |
|
17 |
|
18 |
def hide_settings():
|
|
|
20 |
start_btn = gr.Button("Generate a problem", interactive=False)
|
21 |
solution_acc = gr.Accordion("Solution", open=True)
|
22 |
end_btn = gr.Button("Finish the interview", interactive=True)
|
23 |
+
audio_input = gr.Audio(interactive=True, **default_audio_params)
|
24 |
+
return init_acc, start_btn, solution_acc, end_btn, audio_input
|
25 |
+
|
26 |
+
|
27 |
+
def add_interviewer_message(message):
|
28 |
+
def f(chat):
|
29 |
+
chat.append((None, message))
|
30 |
+
return chat
|
31 |
+
|
32 |
+
return f
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
def hide_solution():
|
36 |
solution_acc = gr.Accordion("Solution", open=False)
|
37 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
38 |
problem_acc = gr.Accordion("Problem statement", open=False)
|
39 |
+
audio_input = gr.Audio(interactive=False, **default_audio_params)
|
40 |
+
return solution_acc, end_btn, problem_acc, audio_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
gr.Markdown("Your coding interview practice AI assistant!")
|
|
|
45 |
# TODO: add other types of interviews (e.g. system design, ML design, behavioral, etc.)
|
46 |
|
47 |
+
with gr.Tab("Coding") as coding_tab:
|
48 |
chat_history = gr.State([])
|
49 |
previous_code = gr.State("")
|
50 |
client = gr.State(None)
|
51 |
+
client_started = gr.State(False)
|
52 |
with gr.Accordion("Settings") as init_acc:
|
53 |
with gr.Row():
|
54 |
with gr.Column():
|
55 |
+
gr.Markdown("##### Problem settings")
|
56 |
+
with gr.Row():
|
57 |
+
gr.Markdown("Difficulty")
|
58 |
+
difficulty_select = gr.Dropdown(
|
59 |
+
label="Select difficulty",
|
60 |
+
choices=["Easy", "Medium", "Hard"],
|
61 |
+
value="Medium",
|
62 |
+
container=False,
|
63 |
+
allow_custom_value=True,
|
64 |
+
)
|
65 |
+
with gr.Row():
|
66 |
+
gr.Markdown("Topic (can type custom value)")
|
67 |
+
topic_select = gr.Dropdown(
|
68 |
+
label="Select topic", choices=topics_list, value="Arrays", container=False, allow_custom_value=True
|
69 |
+
)
|
70 |
+
|
71 |
+
gr.Markdown("##### Assistant settings")
|
72 |
+
with gr.Row():
|
73 |
+
gr.Markdown("Select LLM model to use")
|
74 |
+
model_select = gr.Dropdown(label="Select model", choices=models, value="gpt-3.5-turbo", container=False)
|
75 |
+
with gr.Column(scale=2):
|
76 |
+
requirements = gr.Textbox(label="Requirements", placeholder="Specify additional requirements", lines=5)
|
77 |
start_btn = gr.Button("Generate a problem")
|
78 |
|
79 |
# TODO: select LLM model
|
|
|
82 |
with gr.Accordion("Solution", open=False) as solution_acc:
|
83 |
with gr.Row() as content:
|
84 |
with gr.Column(scale=2):
|
85 |
+
code = gr.Code(
|
86 |
+
label="Please write your code here. Only Python linting is available for now.", language="python", lines=35
|
87 |
)
|
|
|
88 |
with gr.Column(scale=1):
|
89 |
end_btn = gr.Button("Finish the interview", interactive=False)
|
90 |
+
chat = gr.Chatbot(label="Chat", show_label=False, show_share_button=False)
|
91 |
+
audio_input = gr.Audio(interactive=False, **default_audio_params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
audio_output = gr.Audio(label="Play audio", autoplay=True, visible=False)
|
93 |
+
message = gr.Textbox(label="Message", lines=3, visible=False)
|
|
|
94 |
|
95 |
with gr.Accordion("Feedback", open=True) as feedback_acc:
|
96 |
feedback = gr.Markdown()
|
97 |
|
98 |
+
with gr.Tab("Instruction") as instruction_tab:
|
99 |
+
pass
|
100 |
+
|
101 |
+
coding_tab.select(fn=add_interviewer_message(fixed_messages["intro"]), inputs=[chat], outputs=[chat])
|
102 |
+
|
103 |
+
start_btn.click(fn=add_interviewer_message(fixed_messages["start"]), inputs=[chat], outputs=[chat]).then(
|
104 |
fn=get_problem,
|
105 |
inputs=[requirements, difficulty_select, topic_select, model_select],
|
106 |
outputs=[description, chat_history],
|
107 |
scroll_to_output=True,
|
108 |
+
).then(fn=hide_settings, inputs=None, outputs=[init_acc, start_btn, solution_acc, end_btn, audio_input])
|
109 |
|
110 |
+
message.submit(
|
111 |
fn=send_request,
|
112 |
inputs=[code, previous_code, message, chat_history, chat, model_select],
|
113 |
outputs=[chat_history, chat, message, previous_code],
|
114 |
)
|
115 |
|
116 |
+
end_btn.click(
|
117 |
+
fn=add_interviewer_message(fixed_messages["end"]),
|
118 |
+
inputs=[chat],
|
119 |
+
outputs=[chat],
|
120 |
+
).then(
|
121 |
+
fn=end_interview, inputs=[chat_history, model_select], outputs=feedback
|
122 |
+
).then(fn=hide_solution, inputs=None, outputs=[solution_acc, end_btn, problem_acc, audio_input])
|
123 |
|
124 |
audio_input.stop_recording(fn=transcribe_audio, inputs=[audio_input], outputs=[message]).then(
|
125 |
+
fn=lambda: None, inputs=None, outputs=[audio_input]
|
126 |
).then(
|
127 |
fn=send_request,
|
128 |
inputs=[code, previous_code, message, chat_history, chat, model_select],
|
|
|
131 |
|
132 |
chat.change(fn=read_last_message, inputs=[chat], outputs=[audio_output])
|
133 |
|
134 |
+
audio_output.stop(fn=lambda: None, inputs=None, outputs=[audio_output])
|
135 |
|
136 |
+
demo.launch(show_api=False)
|
options.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
languages_list = ["python", "javascript", "html", "css", "typescript", "dockerfile", "shell", "r", "sql"] # limited by gradio for now
|
2 |
topics_list = [
|
3 |
"Arrays",
|
4 |
"Strings",
|
@@ -20,37 +19,18 @@ topics_list = [
|
|
20 |
"Bit Manipulation",
|
21 |
"Binary Search Trees",
|
22 |
"Tries",
|
23 |
-
"Union Find",
|
24 |
-
"Geometry",
|
25 |
-
"Segment Trees",
|
26 |
-
"Game Theory",
|
27 |
-
"Topological Sort",
|
28 |
-
"Fenwick Tree",
|
29 |
-
"Number Theory",
|
30 |
-
"Sliding Window",
|
31 |
-
"Disjoint Set",
|
32 |
-
"Hashing",
|
33 |
-
"Probabilities",
|
34 |
-
"Combinatorics",
|
35 |
-
"Minimax",
|
36 |
-
"Two Pointers",
|
37 |
-
"Suffix Array",
|
38 |
-
"Fast Fourier Transform",
|
39 |
-
"Matrix Operations",
|
40 |
-
"Eulerian Path",
|
41 |
-
"Bellman-Ford Algorithm",
|
42 |
-
"Floyd-Warshall Algorithm",
|
43 |
-
"Prim's Algorithm",
|
44 |
-
"Kruskal's Algorithm",
|
45 |
-
"Rabin-Karp Algorithm",
|
46 |
-
"Z-algorithm",
|
47 |
-
"Manacher's Algorithm",
|
48 |
-
"AVL Trees",
|
49 |
-
"Red-Black Trees",
|
50 |
-
"Splay Trees",
|
51 |
-
"Treaps",
|
52 |
-
"Computational Geometry",
|
53 |
]
|
54 |
models = ["gpt-3.5-turbo"]
|
55 |
# TODO: add more OAI models
|
56 |
# TODO: add more OS models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
topics_list = [
|
2 |
"Arrays",
|
3 |
"Strings",
|
|
|
19 |
"Bit Manipulation",
|
20 |
"Binary Search Trees",
|
21 |
"Tries",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
]
|
23 |
models = ["gpt-3.5-turbo"]
|
24 |
# TODO: add more OAI models
|
25 |
# TODO: add more OS models
|
26 |
+
|
27 |
+
|
28 |
+
fixed_messages = {
|
29 |
+
"intro": "Welcome to the coding interview! I am your AI interview assistant. For the start select the difficulty and topic of the problem you would like to solve. Then click on the 'Generate a problem' button. Good luck!",
|
30 |
+
"start": (
|
31 |
+
"Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have. Good luck! "
|
32 |
+
"Please use the record button to communicate with me. Try to think out loud and record all you comments and questions as if it is the real interview."
|
33 |
+
),
|
34 |
+
"end": "The interview has concluded. Thank you for your participation! In a moment I will provide a detailed feedback on your performance.",
|
35 |
+
"error": "An error occurred. Please try again.",
|
36 |
+
}
|