Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "Great! What’s your background and what field/role are you aiming for?", user_profile
|
| 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, chat_history, user_profile):
|
| 15 |
+
if not user_profile.get("interview_type") or not user_profile.get("field"):
|
| 16 |
+
bot_msg = "Please finish steps 1 and 2 before starting the interview."
|
| 17 |
+
chat_history.append((message, bot_msg))
|
| 18 |
+
return chat_history
|
| 19 |
+
|
| 20 |
+
messages = [
|
| 21 |
+
{"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."}
|
| 22 |
+
]
|
| 23 |
+
for q, a in chat_history:
|
| 24 |
+
messages.append({"role": "user", "content": q})
|
| 25 |
+
messages.append({"role": "assistant", "content": a})
|
| 26 |
+
messages.append({"role": "user", "content": message})
|
| 27 |
+
|
| 28 |
+
response = client.chat_completion(messages, max_tokens=150, stream=False)
|
| 29 |
+
bot_msg = response.choices[0].message.content
|
| 30 |
+
chat_history.append((message, bot_msg))
|
| 31 |
+
return chat_history
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
user_profile = gr.State({"interview_type": "", "field": ""})
|
| 35 |
+
chat_history = gr.State([])
|
| 36 |
+
|
| 37 |
+
gr.Markdown("# 🎤 Welcome to Intervu")
|
| 38 |
+
|
| 39 |
+
# Step 1
|
| 40 |
+
gr.Markdown("### Step 1: Choose Interview Type")
|
| 41 |
+
with gr.Row():
|
| 42 |
+
with gr.Column():
|
| 43 |
+
btn1 = gr.Button("Behavioral")
|
| 44 |
+
btn2 = gr.Button("Technical")
|
| 45 |
+
btn3 = gr.Button("College / Scholarship")
|
| 46 |
+
type_output = gr.Textbox(label="Bot response", interactive=False)
|
| 47 |
+
|
| 48 |
+
btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])
|
| 49 |
+
btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
|
| 50 |
+
btn3.click(set_type, inputs=[gr.Textbox(value="College", visible=False), user_profile], outputs=[type_output, user_profile])
|
| 51 |
+
|
| 52 |
+
# Step 2
|
| 53 |
+
gr.Markdown("### Step 2: Enter Your Background")
|
| 54 |
+
background = gr.Textbox(label="Your background and field/goal")
|
| 55 |
+
background_btn = gr.Button("Submit")
|
| 56 |
+
background_output = gr.Textbox(label="Bot response", interactive=False)
|
| 57 |
+
|
| 58 |
+
background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
|
| 59 |
+
|
| 60 |
+
# Step 3
|
| 61 |
+
gr.Markdown("### Step 3: Start Interview")
|
| 62 |
+
chatbot = gr.Chatbot(label="Interview Bot")
|
| 63 |
+
msg = gr.Textbox(label="Your message")
|
| 64 |
+
send_btn = gr.Button("Send")
|
| 65 |
+
|
| 66 |
+
send_btn.click(respond, inputs=[msg, chat_history, user_profile], outputs=[chatbot], queue=False)
|
| 67 |
+
send_btn.click(lambda: "", None, msg, queue=False)
|
| 68 |
+
|
| 69 |
+
demo.launch()
|