intervu / app.py
maahikachitagi's picture
Update app.py
8a4df17 verified
raw
history blame
2.83 kB
import gradio as gr
from huggingface_hub import InferenceClient
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def set_type(choice, user_profile):
user_profile["interview_type"] = choice.lower()
return f"Great! What’s your background and what field/role are you aiming for?", user_profile
def save_background(info, user_profile):
user_profile["field"] = info
return "Awesome! Type 'start' below to begin your interview.", user_profile
def respond(message, history, user_profile):
if not user_profile["interview_type"] or not user_profile["field"]:
return "Please finish steps 1 and 2 before starting the interview."
messages = [
{
"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."
}
]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
response = client.chat_completion(
messages,
max_tokens=150,
stream=False
)
return response.choices[0].message.content
with gr.Blocks() as demo:
user_profile = gr.State({"interview_type": "", "field": ""})
gr.Markdown("# 🎀 Welcome to Intervu")
# Step 1
gr.Markdown("### Step 1: Choose Interview Type")
with gr.Row():
behavioral_val = gr.Textbox(value="Behavioral", visible=False)
technical_val = gr.Textbox(value="Technical", visible=False)
college_val = gr.Textbox(value="College", visible=False)
btn1 = gr.Button("Behavioral")
btn2 = gr.Button("Technical")
btn3 = gr.Button("College / Scholarship")
type_out = gr.Textbox(label="Bot", interactive=False)
btn1.click(set_type, inputs=[behavioral_val, user_profile], outputs=[type_out, user_profile])
btn2.click(set_type, inputs=[technical_val, user_profile], outputs=[type_out, user_profile])
btn3.click(set_type, inputs=[college_val, user_profile], outputs=[type_out, user_profile])
# Step 2
gr.Markdown("### Step 2: Enter Your Background")
background = gr.Textbox(label="Your background and field/goal")
background_btn = gr.Button("Submit Background")
background_out = gr.Textbox(label="Bot", interactive=False)
background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_out, user_profile])
# Step 3
gr.Markdown("### Step 3: Start Interview")
chatbot = gr.ChatInterface(
fn=lambda msg, hist: respond(msg, hist, user_profile.value),
title="Intervu - AI Interview Practice",
chatbot=gr.Chatbot(label="Interview Bot"),
input_textbox=gr.Textbox(placeholder="Type your answer here..."),
type="messages"
)
demo.launch()