Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,7 +42,11 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
| 42 |
def set_type(choice, user_profile):
|
| 43 |
user_profile.update({
|
| 44 |
"interview_type": choice,
|
| 45 |
-
"state": "idle"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
})
|
| 47 |
return "Great! Whatβs your background and what field/role are you aiming for?", user_profile
|
| 48 |
|
|
@@ -53,71 +57,72 @@ def save_background(info, user_profile):
|
|
| 53 |
|
| 54 |
# ---- Main Respond Logic ----
|
| 55 |
def respond(message, chat_history, user_profile):
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
# Safety:
|
| 59 |
if not user_profile.get("interview_type") or not user_profile.get("field"):
|
| 60 |
chat_history.append((message, "Please finish steps 1 and 2 first."))
|
| 61 |
return chat_history
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
if message == 'start' and state == 'idle':
|
| 67 |
-
interview_type = user_profile['interview_type']
|
| 68 |
-
selected_questions = questions_by_type.get(interview_type, [])
|
| 69 |
|
| 70 |
if not selected_questions:
|
| 71 |
chat_history.append((message, "No questions found for this interview type."))
|
| 72 |
return chat_history
|
| 73 |
|
| 74 |
-
user_profile
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
'state': 'running'
|
| 79 |
-
})
|
| 80 |
|
| 81 |
-
intro_msg = f"Great, let's begin your {interview_type} interview for the {user_profile['field']} role.\nI
|
| 82 |
-
first_q = selected_questions[0]['question']
|
| 83 |
chat_history.append((message, intro_msg))
|
| 84 |
-
chat_history.append(("",
|
| 85 |
return chat_history
|
| 86 |
|
| 87 |
-
#
|
| 88 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
user_profile["state"] = "stopped"
|
| 90 |
-
chat_history.append((message, "Interview stopped.
|
| 91 |
return chat_history
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
if
|
| 95 |
-
if state !=
|
| 96 |
chat_history.append((message, "Feedback is only available after completing the interview."))
|
| 97 |
return chat_history
|
| 98 |
-
|
| 99 |
feedback = generate_feedback(user_profile)
|
| 100 |
chat_history.append((message, feedback))
|
| 101 |
return chat_history
|
| 102 |
|
| 103 |
-
#
|
| 104 |
-
if state ==
|
| 105 |
-
q_index = user_profile[
|
| 106 |
-
questions = user_profile[
|
| 107 |
|
| 108 |
if q_index < len(questions):
|
| 109 |
-
user_profile[
|
| 110 |
-
user_profile[
|
| 111 |
|
| 112 |
-
if user_profile[
|
| 113 |
-
|
| 114 |
-
chat_history.append((message, f"Next question: {
|
| 115 |
else:
|
| 116 |
-
user_profile[
|
| 117 |
-
chat_history.append((message, "β
Interview complete!
|
| 118 |
return chat_history
|
| 119 |
|
| 120 |
-
#
|
| 121 |
messages = [
|
| 122 |
{"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."}
|
| 123 |
]
|
|
@@ -154,7 +159,10 @@ def generate_feedback(user_profile):
|
|
| 154 |
|
| 155 |
# ---- Gradio UI ----
|
| 156 |
with gr.Blocks() as demo:
|
| 157 |
-
user_profile = gr.State({
|
|
|
|
|
|
|
|
|
|
| 158 |
chat_history = gr.State([])
|
| 159 |
|
| 160 |
gr.Markdown("# π€ Welcome to Intervu")
|
|
|
|
| 42 |
def set_type(choice, user_profile):
|
| 43 |
user_profile.update({
|
| 44 |
"interview_type": choice,
|
| 45 |
+
"state": "idle",
|
| 46 |
+
"questions": [],
|
| 47 |
+
"current_q": 0,
|
| 48 |
+
"user_answers": [],
|
| 49 |
+
"field": ""
|
| 50 |
})
|
| 51 |
return "Great! Whatβs your background and what field/role are you aiming for?", user_profile
|
| 52 |
|
|
|
|
| 57 |
|
| 58 |
# ---- Main Respond Logic ----
|
| 59 |
def respond(message, chat_history, user_profile):
|
| 60 |
+
msg = message.strip().lower()
|
| 61 |
+
state = user_profile.get("state", "idle")
|
| 62 |
|
| 63 |
+
# Safety: ensure setup
|
| 64 |
if not user_profile.get("interview_type") or not user_profile.get("field"):
|
| 65 |
chat_history.append((message, "Please finish steps 1 and 2 first."))
|
| 66 |
return chat_history
|
| 67 |
|
| 68 |
+
# START command
|
| 69 |
+
if msg == "start" and state == "idle":
|
| 70 |
+
selected_questions = questions_by_type.get(user_profile['interview_type'], [])
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
if not selected_questions:
|
| 73 |
chat_history.append((message, "No questions found for this interview type."))
|
| 74 |
return chat_history
|
| 75 |
|
| 76 |
+
user_profile["questions"] = selected_questions
|
| 77 |
+
user_profile["current_q"] = 0
|
| 78 |
+
user_profile["user_answers"] = []
|
| 79 |
+
user_profile["state"] = "intro"
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
intro_msg = f"Great, let's begin your {user_profile['interview_type']} interview for the {user_profile['field']} role.\nI'll be asking you several questions to assess your knowledge. Feel free to take your time answering."
|
|
|
|
| 82 |
chat_history.append((message, intro_msg))
|
| 83 |
+
chat_history.append(("", "Type 'next' when you're ready to begin."))
|
| 84 |
return chat_history
|
| 85 |
|
| 86 |
+
# INTRO β waiting for user to say "next"
|
| 87 |
+
if msg == "next" and state == "intro":
|
| 88 |
+
user_profile["state"] = "interviewing"
|
| 89 |
+
first_question = user_profile['questions'][0]['question']
|
| 90 |
+
chat_history.append((message, f"First question: {first_question}"))
|
| 91 |
+
return chat_history
|
| 92 |
+
|
| 93 |
+
# STOP anytime during interviewing
|
| 94 |
+
if msg == "stop" and state in ["intro", "interviewing"]:
|
| 95 |
user_profile["state"] = "stopped"
|
| 96 |
+
chat_history.append((message, "Interview stopped. You may type 'start' to begin again."))
|
| 97 |
return chat_history
|
| 98 |
|
| 99 |
+
# FEEDBACK command
|
| 100 |
+
if msg == "feedback":
|
| 101 |
+
if state != "completed":
|
| 102 |
chat_history.append((message, "Feedback is only available after completing the interview."))
|
| 103 |
return chat_history
|
|
|
|
| 104 |
feedback = generate_feedback(user_profile)
|
| 105 |
chat_history.append((message, feedback))
|
| 106 |
return chat_history
|
| 107 |
|
| 108 |
+
# INTERVIEWING STATE LOGIC
|
| 109 |
+
if state == "interviewing":
|
| 110 |
+
q_index = user_profile["current_q"]
|
| 111 |
+
questions = user_profile["questions"]
|
| 112 |
|
| 113 |
if q_index < len(questions):
|
| 114 |
+
user_profile["user_answers"].append(message)
|
| 115 |
+
user_profile["current_q"] += 1
|
| 116 |
|
| 117 |
+
if user_profile["current_q"] < len(questions):
|
| 118 |
+
next_q = questions[user_profile["current_q"]]["question"]
|
| 119 |
+
chat_history.append((message, f"Next question: {next_q}"))
|
| 120 |
else:
|
| 121 |
+
user_profile["state"] = "completed"
|
| 122 |
+
chat_history.append((message, "β
Interview complete! Type 'feedback' if you'd like a performance analysis."))
|
| 123 |
return chat_history
|
| 124 |
|
| 125 |
+
# ANY OTHER MESSAGE (idle, stopped, etc) β small talk fallback using LLM
|
| 126 |
messages = [
|
| 127 |
{"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."}
|
| 128 |
]
|
|
|
|
| 159 |
|
| 160 |
# ---- Gradio UI ----
|
| 161 |
with gr.Blocks() as demo:
|
| 162 |
+
user_profile = gr.State({
|
| 163 |
+
"interview_type": "", "field": "", "state": "idle",
|
| 164 |
+
"questions": [], "current_q": 0, "user_answers": []
|
| 165 |
+
})
|
| 166 |
chat_history = gr.State([])
|
| 167 |
|
| 168 |
gr.Markdown("# π€ Welcome to Intervu")
|