Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546473 unmodified lines515253545556575859606162import gradio as grfrom huggingface_hub import InferenceClient# Initialize your modelclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")# Step 1: Set interview typedef set_type(choice, user_profile):user_profile["interview_type"] = choicereturn "Great! Whatβs your background and what field/role are you aiming for?", user_profile# Step 2: Save background infodef save_background(info, user_profile):user_profile["field"] = inforeturn "Awesome! Type 'start' below to begin your interview.", user_profile# Step 3: Respond to userdef respond(message, history, user_profile):if not user_profile.get("interview_type") or not user_profile.get("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# Build UIwith gr.Blocks() as demo:user_profile = gr.State({"interview_type": "", "field": ""})gr.Markdown("# π€ Welcome to Intervu")# Step 1gr.Markdown("### Step 1: Choose Interview Type")with gr.Row():btn1 = gr.Button("Behavioral")btn2 = gr.Button("Technical")btn3 = gr.Button("College / Scholarship")type_output = gr.Textbox(label="Bot", interactive=False)btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])3 unmodified linesgr.Markdown("### Step 2: Enter Your Background")background = gr.Textbox(label="Your background and field/goal")background_btn = gr.Button("Submit")background_output = gr.Textbox(label="Bot", interactive=False)background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])# Step 3gr.Markdown("### Step 3: Start Interview")chatbot = gr.ChatInterface(fn=lambda msg, hist: respond(msg, hist, user_profile.value), title="Intervu - AI Interview Practice", type="messages")demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748493 unmodified lines5354555657585960616263646566676869import gradio as grfrom huggingface_hub import InferenceClientclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def set_type(choice, user_profile):user_profile["interview_type"] = choicereturn "Great! Whatβs your background and what field/role are you aiming for?", user_profiledef save_background(info, user_profile):user_profile["field"] = inforeturn "Awesome! Type 'start' below to begin your interview.", user_profiledef respond(message, chat_history, user_profile):if not user_profile.get("interview_type") or not user_profile.get("field"):bot_msg = "Please finish steps 1 and 2 before starting the interview."chat_history.append((message, bot_msg))return chat_historymessages = [{"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."}]for q, a in chat_history:messages.append({"role": "user", "content": q})messages.append({"role": "assistant", "content": a})messages.append({"role": "user", "content": message})response = client.chat_completion(messages, max_tokens=150, stream=False)bot_msg = response.choices[0].message.contentchat_history.append((message, bot_msg))return chat_historywith gr.Blocks() as demo:user_profile = gr.State({"interview_type": "", "field": ""})chat_history = gr.State([])gr.Markdown("# π€ Welcome to Intervu")# Step 1gr.Markdown("### Step 1: Choose Interview Type")with gr.Row():with gr.Column():btn1 = gr.Button("Behavioral")btn2 = gr.Button("Technical")btn3 = gr.Button("College / Scholarship")type_output = gr.Textbox(label="Bot response", interactive=False)btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])3 unmodified linesgr.Markdown("### Step 2: Enter Your Background")background = gr.Textbox(label="Your background and field/goal")background_btn = gr.Button("Submit")background_output = gr.Textbox(label="Bot response", interactive=False)background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])# Step 3gr.Markdown("### Step 3: Start Interview")chatbot = gr.Chatbot(label="Interview Bot")msg = gr.Textbox(label="Your message")send_btn = gr.Button("Send")send_btn.click(respond, inputs=[msg, chat_history, user_profile], outputs=[chatbot], queue=False)send_btn.click(lambda: "", None, msg, queue=False)demo.launch()
app.py+24-17