Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,133 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
|
| 5 |
|
| 6 |
-
def respond(message, history):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
chatbot.launch()
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
|
| 5 |
|
| 6 |
+
# def respond(message, history):
|
| 7 |
+
# messages = [{"role": "system", "content": "You are a professional Interviewer and you are asking questions based on interview choices"}]
|
| 8 |
+
# if history:
|
| 9 |
+
# messages.extend(history)
|
| 10 |
+
# messages.append({"role": "user", "content": message})
|
| 11 |
|
| 12 |
+
# response = ""
|
| 13 |
+
# for message in client.chat_completion(
|
| 14 |
+
# messages,
|
| 15 |
+
# max_tokens=100,
|
| 16 |
+
# stream=True,
|
| 17 |
|
| 18 |
+
# ):
|
| 19 |
+
# token = message.choices[0].delta.content
|
| 20 |
+
# response += token
|
| 21 |
+
# yield response
|
| 22 |
+
|
| 23 |
+
# chatbot = gr.ChatInterface(respond, type="messages")
|
| 24 |
+
# chatbot.launch()
|
| 25 |
+
import gradio as gr
|
| 26 |
+
|
| 27 |
+
# In-memory user profile
|
| 28 |
+
user_profile = {
|
| 29 |
+
"interview_type": "",
|
| 30 |
+
"field": "",
|
| 31 |
+
"mode": "",
|
| 32 |
+
"responses": []
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# Question bank
|
| 36 |
+
questions = {
|
| 37 |
+
"technical": {
|
| 38 |
+
"software": [
|
| 39 |
+
"Can you explain a recent project where you solved a technical challenge?",
|
| 40 |
+
"How would you optimize a slow-running algorithm?"
|
| 41 |
+
],
|
| 42 |
+
"general": [
|
| 43 |
+
"Explain Big O Notation.",
|
| 44 |
+
"Whatβs a common bug and how do you fix it?"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
"behavioral": {
|
| 48 |
+
"general": [
|
| 49 |
+
"Tell me about a time you had to overcome a challenge.",
|
| 50 |
+
"How do you handle feedback?"
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
"college": {
|
| 54 |
+
"general": [
|
| 55 |
+
"Why do you want to attend this school?",
|
| 56 |
+
"What extracurricular activity means the most to you and why?"
|
| 57 |
+
]
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
# Phase 1: Choose interview type
|
| 62 |
+
def set_type(choice):
|
| 63 |
+
user_profile["interview_type"] = choice.lower()
|
| 64 |
+
return "Great! Whatβs your background and what field/role are you aiming for?"
|
| 65 |
+
|
| 66 |
+
# Phase 2: Save background
|
| 67 |
+
def save_background(info):
|
| 68 |
+
user_profile["field"] = info
|
| 69 |
+
return "Would you like to continue with Text, Audio, or Webcam interview?"
|
| 70 |
+
|
| 71 |
+
# Phase 3: Set mode
|
| 72 |
+
def set_mode(choice):
|
| 73 |
+
user_profile["mode"] = choice.lower()
|
| 74 |
+
return f"Starting {choice} interview... Type 'done' anytime to finish."
|
| 75 |
+
|
| 76 |
+
# Phase 4: Ask question
|
| 77 |
+
def start_interview(user_input):
|
| 78 |
+
if user_input.lower() == "done":
|
| 79 |
+
return "Interview finished! We'll provide feedback shortly."
|
| 80 |
+
|
| 81 |
+
user_profile["responses"].append(user_input)
|
| 82 |
+
|
| 83 |
+
itype = user_profile["interview_type"]
|
| 84 |
+
field = user_profile["field"].lower()
|
| 85 |
+
|
| 86 |
+
field_key = "software" if "software" in field else "general"
|
| 87 |
+
question_list = questions.get(itype, {}).get(field_key, [])
|
| 88 |
+
|
| 89 |
+
if len(user_profile["responses"]) < len(question_list):
|
| 90 |
+
return question_list[len(user_profile["responses"])]
|
| 91 |
+
else:
|
| 92 |
+
return "Thank you! You've completed all questions. Type 'done' to finish."
|
| 93 |
+
|
| 94 |
+
# UI construction
|
| 95 |
+
with gr.Blocks() as demo:
|
| 96 |
+
gr.Markdown("# π€ Welcome to Intervu")
|
| 97 |
+
|
| 98 |
+
with gr.Row():
|
| 99 |
+
gr.Markdown("## Step 1: Choose Interview Type")
|
| 100 |
+
type_out = gr.Textbox(label="Bot Response")
|
| 101 |
+
|
| 102 |
+
with gr.Row():
|
| 103 |
+
btn1 = gr.Button("Behavioral")
|
| 104 |
+
btn2 = gr.Button("Technical")
|
| 105 |
+
btn3 = gr.Button("College / Scholarship")
|
| 106 |
+
|
| 107 |
+
btn1.click(set_type, inputs=[], outputs=type_out, _js="() => 'Behavioral'")
|
| 108 |
+
btn2.click(set_type, inputs=[], outputs=type_out, _js="() => 'Technical'")
|
| 109 |
+
btn3.click(set_type, inputs=[], outputs=type_out, _js="() => 'College'")
|
| 110 |
+
|
| 111 |
+
gr.Markdown("## Step 2: Enter Background")
|
| 112 |
+
background = gr.Textbox(label="Your background + field/goal")
|
| 113 |
+
background_btn = gr.Button("Submit Background")
|
| 114 |
+
mode_out = gr.Textbox(label="Bot Response")
|
| 115 |
+
|
| 116 |
+
background_btn.click(save_background, inputs=background, outputs=mode_out)
|
| 117 |
+
|
| 118 |
+
gr.Markdown("## Step 3: Choose Mode")
|
| 119 |
+
btn_text = gr.Button("Text")
|
| 120 |
+
btn_audio = gr.Button("Audio (WIP)")
|
| 121 |
+
btn_webcam = gr.Button("Webcam (WIP)")
|
| 122 |
+
mode_feedback = gr.Textbox(label="Bot Response")
|
| 123 |
+
|
| 124 |
+
btn_text.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Text'")
|
| 125 |
+
btn_audio.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Audio'")
|
| 126 |
+
btn_webcam.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Webcam'")
|
| 127 |
+
|
| 128 |
+
gr.Markdown("## Step 4: Text Interview")
|
| 129 |
+
user_input = gr.Textbox(label="Your Response")
|
| 130 |
+
bot_reply = gr.Textbox(label="Bot Question")
|
| 131 |
+
user_input.submit(start_interview, inputs=user_input, outputs=bot_reply)
|
| 132 |
|
| 133 |
+
demo.launch()
|
|
|