Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232412327282930313233453536373839404142434445464748495051525354555657586789101112616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657133# import gradio as gr# from huggingface_hub import InferenceClient
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
# def respond(message, history):# messages = [{"role": "system", "content": "You are a professional Interviewer and you are asking questions based on interview choices"}]# if history:# messages.extend(history)# messages.append({"role": "user", "content": message}) # response = ""# for message in client.chat_completion(# messages,# max_tokens=100,# stream=True, # ):# token = message.choices[0].delta.content# response += token# yield response
# chatbot = gr.ChatInterface(respond, type="messages")# chatbot.launch() import gradio as grfrom huggingface_hub import InferenceClient
# In-memory user profileuser_profile = { "interview_type": "", "field": "", "mode": "", "responses": []}client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
# Question bankquestions = { "technical": { "software": [ "Can you explain a recent project where you solved a technical challenge?", "How would you optimize a slow-running algorithm?" ], "general": [ "Explain Big O Notation.", "Whatβs a common bug and how do you fix it?" ] }, "behavioral": { "general": [ "Tell me about a time you had to overcome a challenge.", "How do you handle feedback?" ] }, "college": { "general": [ "Why do you want to attend this school?", "What extracurricular activity means the most to you and why?" ] }user_profile = { "interview_type": None, "field": None, "mode": "text", "stage": "select_type", # stages: select_type β get_background β interview β done}
# Phase 1: Choose interview typedef set_type(choice): user_profile["interview_type"] = choice.lower() return "Great! Whatβs your background and what field/role are you aiming for?"
# Phase 2: Save backgrounddef save_background(info): user_profile["field"] = info return "Would you like to continue with Text, Audio, or Webcam interview?"
# Phase 3: Set modedef set_mode(choice): user_profile["mode"] = choice.lower() return f"Starting {choice} interview... Type 'done' anytime to finish."
# Phase 4: Ask questiondef start_interview(user_input): if user_input.lower() == "done": return "Interview finished! We'll provide feedback shortly."
user_profile["responses"].append(user_input)
itype = user_profile["interview_type"] field = user_profile["field"].lower()
field_key = "software" if "software" in field else "general" question_list = questions.get(itype, {}).get(field_key, [])
if len(user_profile["responses"]) < len(question_list): return question_list[len(user_profile["responses"])] else: return "Thank you! You've completed all questions. Type 'done' to finish."
# UI constructionwith gr.Blocks() as demo: gr.Markdown("# π€ Welcome to Intervu")
with gr.Row(): gr.Markdown("## Step 1: Choose Interview Type") type_out = gr.Textbox(label="Bot Response")
with gr.Row(): btn1 = gr.Button("Behavioral") btn2 = gr.Button("Technical") btn3 = gr.Button("College / Scholarship")
btn1.click(set_type, inputs=[], outputs=type_out, _js="() => 'Behavioral'") btn2.click(set_type, inputs=[], outputs=type_out, _js="() => 'Technical'") btn3.click(set_type, inputs=[], outputs=type_out, _js="() => 'College'")
gr.Markdown("## Step 2: Enter Background") background = gr.Textbox(label="Your background + field/goal") background_btn = gr.Button("Submit Background") mode_out = gr.Textbox(label="Bot Response")
background_btn.click(save_background, inputs=background, outputs=mode_out)
gr.Markdown("## Step 3: Choose Mode") btn_text = gr.Button("Text") btn_audio = gr.Button("Audio (WIP)") btn_webcam = gr.Button("Webcam (WIP)") mode_feedback = gr.Textbox(label="Bot Response")
btn_text.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Text'") btn_audio.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Audio'") btn_webcam.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Webcam'")
gr.Markdown("## Step 4: Text Interview") user_input = gr.Textbox(label="Your Response") bot_reply = gr.Textbox(label="Bot Question") user_input.submit(start_interview, inputs=user_input, outputs=bot_reply)def respond(message, history): global user_profile
# Stage 1: Choose interview type if user_profile["stage"] == "select_type": user_profile["interview_type"] = message.lower() user_profile["stage"] = "get_background" yield f"Great! Whatβs your background and what field are you aiming for?" return
# Stage 2: Get background info elif user_profile["stage"] == "get_background": user_profile["field"] = message user_profile["stage"] = "interview" yield f"Thanks! Letβs begin your {user_profile['interview_type']} interview. Type 'start' to begin." return
# Stage 3: Start asking interview questions elif user_profile["stage"] == "interview": if message.lower() == "start": intro = f"Letβs begin! Iβll ask you questions based on a {user_profile['interview_type']} interview in {user_profile['field']}." return_stream = client.text_generation( f"Ask a good first interview question for a {user_profile['interview_type']} interview in the {user_profile['field']} field.", max_tokens=100, stream=True ) for token in return_stream: yield intro + "\n\n" + token elif message.lower() == "done": user_profile["stage"] = "done" yield "Thanks for completing the interview! Iβll now evaluate your performance... (WIP)" else: messages = [{"role": "system", "content": "You are a professional interviewer. Give feedback or ask follow-up questions."}] messages.extend(history) messages.append({"role": "user", "content": message}) response = "" for message in client.chat_completion(messages, max_tokens=100, stream=True): token = message.choices[0].delta.content response += token yield response
chatbot = gr.ChatInterface(respond, type="messages", title="Intervu - AI Interview Practice")chatbot.launch()
demo.launch()app.py+51-127