Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,21 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
| 4 |
user_profile = {
|
| 5 |
"interview_type": "",
|
| 6 |
"field": "",
|
| 7 |
-
"mode": ""
|
| 8 |
-
"responses": []
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
# Question bank
|
| 12 |
-
questions = {
|
| 13 |
-
"technical": {
|
| 14 |
-
"software": [
|
| 15 |
-
"Can you explain a recent project where you solved a technical challenge?",
|
| 16 |
-
"How would you optimize a slow-running algorithm?"
|
| 17 |
-
],
|
| 18 |
-
"general": [
|
| 19 |
-
"Explain Big O Notation.",
|
| 20 |
-
"Whatβs a common bug and how do you fix it?"
|
| 21 |
-
]
|
| 22 |
-
},
|
| 23 |
-
"behavioral": {
|
| 24 |
-
"general": [
|
| 25 |
-
"Tell me about a time you had to overcome a challenge.",
|
| 26 |
-
"How do you handle feedback?"
|
| 27 |
-
]
|
| 28 |
-
},
|
| 29 |
-
"college": {
|
| 30 |
-
"general": [
|
| 31 |
-
"Why do you want to attend this school?",
|
| 32 |
-
"What extracurricular activity means the most to you and why?"
|
| 33 |
-
]
|
| 34 |
-
}
|
| 35 |
}
|
| 36 |
|
| 37 |
-
#
|
| 38 |
def set_type(choice):
|
| 39 |
user_profile["interview_type"] = choice.lower()
|
| 40 |
return "Great! Whatβs your background and what field/role are you aiming for?"
|
|
|
|
| 41 |
def set_type_behavioral():
|
| 42 |
return set_type("Behavioral")
|
| 43 |
|
|
@@ -47,72 +25,58 @@ def set_type_technical():
|
|
| 47 |
def set_type_college():
|
| 48 |
return set_type("College")
|
| 49 |
|
| 50 |
-
#
|
| 51 |
def save_background(info):
|
| 52 |
user_profile["field"] = info
|
| 53 |
-
return "
|
| 54 |
-
|
| 55 |
-
# Phase 3: Set mode
|
| 56 |
-
def set_mode(choice):
|
| 57 |
-
user_profile["mode"] = choice.lower()
|
| 58 |
-
return f"Starting {choice} interview... Type 'done' anytime to finish."
|
| 59 |
-
|
| 60 |
-
# Phase 4: Ask question
|
| 61 |
-
def start_interview(user_input):
|
| 62 |
-
if user_input.lower() == "done":
|
| 63 |
-
return "Interview finished! We'll provide feedback shortly."
|
| 64 |
-
|
| 65 |
-
user_profile["responses"].append(user_input)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
gr.Markdown("# π€ Welcome to Intervu")
|
| 81 |
|
| 82 |
-
|
| 83 |
-
gr.Markdown("## Step 1: Choose Interview Type")
|
| 84 |
-
type_out = gr.Textbox(label="Bot Response")
|
| 85 |
-
|
| 86 |
with gr.Row():
|
| 87 |
btn1 = gr.Button("Behavioral")
|
| 88 |
btn2 = gr.Button("Technical")
|
| 89 |
btn3 = gr.Button("College / Scholarship")
|
|
|
|
| 90 |
|
| 91 |
btn1.click(set_type_behavioral, outputs=type_out)
|
| 92 |
btn2.click(set_type_technical, outputs=type_out)
|
| 93 |
btn3.click(set_type_college, outputs=type_out)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
background = gr.Textbox(label="Your background + field/goal")
|
| 98 |
-
background_btn = gr.Button("Submit Background")
|
| 99 |
-
mode_out = gr.Textbox(label="Bot Response")
|
| 100 |
-
|
| 101 |
-
background_btn.click(save_background, inputs=background, outputs=mode_out)
|
| 102 |
-
|
| 103 |
-
gr.Markdown("## Step 3: Choose Mode")
|
| 104 |
-
btn_text = gr.Button("Text")
|
| 105 |
-
btn_audio = gr.Button("Audio (WIP)")
|
| 106 |
-
btn_webcam = gr.Button("Webcam (WIP)")
|
| 107 |
-
mode_feedback = gr.Textbox(label="Bot Response")
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
gr.Markdown("## Step 4: Text Interview")
|
| 114 |
-
user_input = gr.Textbox(label="Your Response")
|
| 115 |
-
bot_reply = gr.Textbox(label="Bot Question")
|
| 116 |
-
user_input.submit(start_interview, inputs=user_input, outputs=bot_reply)
|
| 117 |
|
| 118 |
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Initialize LLM client
|
| 5 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
+
|
| 7 |
+
# User profile state
|
| 8 |
user_profile = {
|
| 9 |
"interview_type": "",
|
| 10 |
"field": "",
|
| 11 |
+
"mode": "text"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
+
# Step 1: Set interview type
|
| 15 |
def set_type(choice):
|
| 16 |
user_profile["interview_type"] = choice.lower()
|
| 17 |
return "Great! Whatβs your background and what field/role are you aiming for?"
|
| 18 |
+
|
| 19 |
def set_type_behavioral():
|
| 20 |
return set_type("Behavioral")
|
| 21 |
|
|
|
|
| 25 |
def set_type_college():
|
| 26 |
return set_type("College")
|
| 27 |
|
| 28 |
+
# Step 2: Save background info
|
| 29 |
def save_background(info):
|
| 30 |
user_profile["field"] = info
|
| 31 |
+
return "Awesome! Type 'start' below to begin your interview."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Step 3: Launch chat interface with interview context
|
| 34 |
+
def chat_bot():
|
| 35 |
+
def respond(message, history):
|
| 36 |
+
messages = [
|
| 37 |
+
{"role": "system", "content": f"You are a professional interviewer for a {user_profile['interview_type']} interview in the {user_profile['field']} field."}
|
| 38 |
+
]
|
| 39 |
+
if history:
|
| 40 |
+
messages.extend(history)
|
| 41 |
+
messages.append({"role": "user", "content": message})
|
| 42 |
+
|
| 43 |
+
response = ""
|
| 44 |
+
for msg in client.chat_completion(
|
| 45 |
+
messages,
|
| 46 |
+
max_tokens=100,
|
| 47 |
+
stream=True
|
| 48 |
+
):
|
| 49 |
+
token = msg.choices[0].delta.content
|
| 50 |
+
response += token
|
| 51 |
+
yield response
|
| 52 |
+
|
| 53 |
+
gr.ChatInterface(respond, title="Intervu - AI Interview Practice").launch()
|
| 54 |
+
|
| 55 |
+
# Build UI
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
gr.Markdown("# π€ Welcome to Intervu")
|
| 58 |
|
| 59 |
+
gr.Markdown("### Step 1: Choose Interview Type")
|
|
|
|
|
|
|
|
|
|
| 60 |
with gr.Row():
|
| 61 |
btn1 = gr.Button("Behavioral")
|
| 62 |
btn2 = gr.Button("Technical")
|
| 63 |
btn3 = gr.Button("College / Scholarship")
|
| 64 |
+
type_out = gr.Textbox(label="Bot", interactive=False)
|
| 65 |
|
| 66 |
btn1.click(set_type_behavioral, outputs=type_out)
|
| 67 |
btn2.click(set_type_technical, outputs=type_out)
|
| 68 |
btn3.click(set_type_college, outputs=type_out)
|
| 69 |
|
| 70 |
+
gr.Markdown("### Step 2: Enter Your Background")
|
| 71 |
+
background = gr.Textbox(label="Your background and field/goal")
|
| 72 |
+
background_btn = gr.Button("Submit")
|
| 73 |
+
background_out = gr.Textbox(label="Bot", interactive=False)
|
| 74 |
|
| 75 |
+
background_btn.click(save_background, inputs=background, outputs=background_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
gr.Markdown("### Step 3: Start Your Interview")
|
| 78 |
+
start_btn = gr.Button("Launch Chat Interview")
|
| 79 |
+
start_btn.click(fn=chat_bot, inputs=[], outputs=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
demo.launch()
|
| 82 |
+
|