Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,78 +1,62 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
| 4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
|
|
|
|
| 6 |
def set_type(choice, user_profile):
|
| 7 |
-
user_profile["interview_type"] = choice
|
| 8 |
-
return
|
| 9 |
|
|
|
|
| 10 |
def save_background(info, user_profile):
|
| 11 |
user_profile["field"] = info
|
| 12 |
return "Awesome! Type 'start' below to begin your interview.", user_profile
|
| 13 |
|
|
|
|
| 14 |
def respond(message, history, user_profile):
|
| 15 |
-
if not user_profile
|
| 16 |
return "Please finish steps 1 and 2 before starting the interview."
|
| 17 |
|
| 18 |
messages = [
|
| 19 |
-
{
|
| 20 |
-
"role": "system",
|
| 21 |
-
"content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in the {user_profile['field']} field."
|
| 22 |
-
}
|
| 23 |
]
|
| 24 |
if history:
|
| 25 |
messages.extend(history)
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
| 28 |
-
response = client.chat_completion(
|
| 29 |
-
messages,
|
| 30 |
-
max_tokens=150,
|
| 31 |
-
stream=False
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
return response.choices[0].message.content
|
| 35 |
|
| 36 |
-
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
user_profile = gr.State({"interview_type": "", "field": ""})
|
| 39 |
|
| 40 |
gr.Markdown("# π€ Welcome to Intervu")
|
| 41 |
-
|
| 42 |
# Step 1
|
| 43 |
gr.Markdown("### Step 1: Choose Interview Type")
|
| 44 |
with gr.Row():
|
| 45 |
-
behavioral_val = gr.Textbox(value="Behavioral", visible=False)
|
| 46 |
-
technical_val = gr.Textbox(value="Technical", visible=False)
|
| 47 |
-
college_val = gr.Textbox(value="College", visible=False)
|
| 48 |
-
|
| 49 |
btn1 = gr.Button("Behavioral")
|
| 50 |
btn2 = gr.Button("Technical")
|
| 51 |
btn3 = gr.Button("College / Scholarship")
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
btn2.click(set_type, inputs=[technical_val, user_profile], outputs=[type_out, user_profile])
|
| 57 |
-
btn3.click(set_type, inputs=[college_val, user_profile], outputs=[type_out, user_profile])
|
| 58 |
|
| 59 |
# Step 2
|
| 60 |
gr.Markdown("### Step 2: Enter Your Background")
|
| 61 |
background = gr.Textbox(label="Your background and field/goal")
|
| 62 |
-
background_btn = gr.Button("Submit
|
| 63 |
-
|
| 64 |
|
| 65 |
-
background_btn.click(save_background, inputs=[background, user_profile], outputs=[
|
| 66 |
|
| 67 |
# Step 3
|
| 68 |
gr.Markdown("### Step 3: Start Interview")
|
| 69 |
-
chatbot = gr.ChatInterface(
|
| 70 |
-
fn=lambda msg, hist: respond(msg, hist, user_profile.value),
|
| 71 |
-
title="Intervu - AI Interview Practice",
|
| 72 |
-
chatbot=gr.Chatbot(label="Interview Bot"),
|
| 73 |
-
input_textbox=gr.Textbox(placeholder="Type your answer here..."),
|
| 74 |
-
type="messages"
|
| 75 |
-
)
|
| 76 |
|
| 77 |
demo.launch()
|
| 78 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Initialize your model
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
+
# Step 1: Set interview type
|
| 8 |
def set_type(choice, user_profile):
|
| 9 |
+
user_profile["interview_type"] = choice
|
| 10 |
+
return "Great! Whatβs your background and what field/role are you aiming for?", user_profile
|
| 11 |
|
| 12 |
+
# Step 2: Save background info
|
| 13 |
def save_background(info, user_profile):
|
| 14 |
user_profile["field"] = info
|
| 15 |
return "Awesome! Type 'start' below to begin your interview.", user_profile
|
| 16 |
|
| 17 |
+
# Step 3: Respond to user
|
| 18 |
def respond(message, history, user_profile):
|
| 19 |
+
if not user_profile.get("interview_type") or not user_profile.get("field"):
|
| 20 |
return "Please finish steps 1 and 2 before starting the interview."
|
| 21 |
|
| 22 |
messages = [
|
| 23 |
+
{"role": "system", "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in the {user_profile['field']} field."}
|
|
|
|
|
|
|
|
|
|
| 24 |
]
|
| 25 |
if history:
|
| 26 |
messages.extend(history)
|
| 27 |
messages.append({"role": "user", "content": message})
|
| 28 |
|
| 29 |
+
response = client.chat_completion(messages, max_tokens=150, stream=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return response.choices[0].message.content
|
| 31 |
|
| 32 |
+
# Build UI
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
user_profile = gr.State({"interview_type": "", "field": ""})
|
| 35 |
|
| 36 |
gr.Markdown("# π€ Welcome to Intervu")
|
| 37 |
+
|
| 38 |
# Step 1
|
| 39 |
gr.Markdown("### Step 1: Choose Interview Type")
|
| 40 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
btn1 = gr.Button("Behavioral")
|
| 42 |
btn2 = gr.Button("Technical")
|
| 43 |
btn3 = gr.Button("College / Scholarship")
|
| 44 |
+
type_output = gr.Textbox(label="Bot", interactive=False)
|
| 45 |
|
| 46 |
+
btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])
|
| 47 |
+
btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
|
| 48 |
+
btn3.click(set_type, inputs=[gr.Textbox(value="College", visible=False), user_profile], outputs=[type_output, user_profile])
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Step 2
|
| 51 |
gr.Markdown("### Step 2: Enter Your Background")
|
| 52 |
background = gr.Textbox(label="Your background and field/goal")
|
| 53 |
+
background_btn = gr.Button("Submit")
|
| 54 |
+
background_output = gr.Textbox(label="Bot", interactive=False)
|
| 55 |
|
| 56 |
+
background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
|
| 57 |
|
| 58 |
# Step 3
|
| 59 |
gr.Markdown("### Step 3: Start Interview")
|
| 60 |
+
chatbot = gr.ChatInterface(fn=lambda msg, hist: respond(msg, hist, user_profile.value), title="Intervu - AI Interview Practice", type="messages")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
demo.launch()
|
|
|