intervu / app.py
maahikachitagi's picture
Update app.py
512a608 verified
raw
history blame
2.34 kB
import gradio as gr
from huggingface_hub import InferenceClient
# Initialize LLM client
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
# User profile state
user_profile = {
"interview_type": "",
"field": "",
"mode": "text"
}
# Step 1: Set interview type
def set_type(choice):
user_profile["interview_type"] = choice.lower()
return "Great! What’s your background and what field/role are you aiming for?"
def set_type_behavioral():
return set_type("Behavioral")
def set_type_technical():
return set_type("Technical")
def set_type_college():
return set_type("College")
# Step 2: Save background info
def save_background(info):
user_profile["field"] = info
return "Awesome! Type 'start' below to begin your interview."
# Step 3: Response logic for embedded Chatbot
def respond(message, history):
messages = [
{"role": "system", "content": f"You are a professional interviewer for a {user_profile['interview_type']} interview in the {user_profile['field']} field."}
]
if history:
messages.extend(history)
messages.append({"role": "user", "content": message})
response = ""
for msg in client.chat_completion(
messages,
max_tokens=100,
stream=True
):
token = msg.choices[0].delta.content
response += token
yield response
# Build UI
with gr.Blocks() as demo:
gr.Markdown("# 🎀 Welcome to Intervu")
gr.Markdown("### Step 1: Choose Interview Type")
with gr.Row():
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_behavioral, outputs=type_out)
btn2.click(set_type_technical, outputs=type_out)
btn3.click(set_type_college, outputs=type_out)
gr.Markdown("### Step 2: Enter Your Background")
background = gr.Textbox(label="Your background and field/goal")
background_btn = gr.Button("Submit")
background_out = gr.Textbox(label="Bot", interactive=False)
background_btn.click(save_background, inputs=background, outputs=background_out)
gr.Markdown("### Step 3: Start Your Interview")
chatbot = gr.ChatInterface(respond, title="Intervu - AI Interview Practice")
demo.launch()