Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import gradio as grfrom huggingface_hub import InferenceClientclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLMuser_profile = {"interview_type": None,"field": None,"mode": "text","stage": "select_type", # stages: select_type β get_background β interview β done}def respond(message, history):global user_profile# Stage 1: Choose interview typeif 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 infoelif user_profile["stage"] == "get_background":user_profile["field"] = messageuser_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 questionselif 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" + tokenelif 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.contentresponse += tokenyield responsechatbot = gr.ChatInterface(respond, type="messages", title="Intervu - AI Interview Practice")chatbot.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import gradio as gr# In-memory user profileuser_profile = {"interview_type": "","field": "","mode": "","responses": []}# 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?"]}}# 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"] = inforeturn "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)demo.launch()
app.py+103-51