maahikachitagi commited on
Commit
914a8d3
·
verified ·
1 Parent(s): 182d403

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -77
app.py CHANGED
@@ -3,11 +3,10 @@ from huggingface_hub import InferenceClient
3
  import re
4
  import random
5
 
6
- # uploading and cleaning the knowledge txt file
7
  def load_questions(file_path):
8
  with open(file_path, 'r') as f:
9
  data = f.read()
10
-
11
  question_blocks = re.split(r'Question:\s*', data)[1:]
12
  questions = []
13
  for block in question_blocks:
@@ -20,7 +19,7 @@ def load_questions(file_path):
20
 
21
  all_questions = load_questions('knowledge.txt')
22
 
23
- # creating the questions based on each interview
24
  questions_by_type = {
25
  'Technical': [q for q in all_questions if any(keyword in q['question'].lower() for keyword in [
26
  'function', 'linked list', 'url', 'rest', 'graphql', 'garbage', 'cap theorem', 'sql', 'hash table',
@@ -35,7 +34,7 @@ questions_by_type = {
35
 
36
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
37
 
38
- # setting up the users profile
39
  def set_type(choice, user_profile):
40
  user_profile["interview_type"] = choice
41
  return "Great! What’s your background and what field/role are you aiming for?", user_profile
@@ -52,7 +51,6 @@ def respond(message, chat_history, user_profile):
52
  chat_history.append((message, bot_msg))
53
  return chat_history
54
 
55
- # interview process
56
  if message_lower == 'start':
57
  interview_type = user_profile['interview_type']
58
  selected_questions = questions_by_type.get(interview_type, [])
@@ -72,14 +70,13 @@ def respond(message, chat_history, user_profile):
72
 
73
  if message_lower == 'stop' and user_profile.get("interview_in_progress"):
74
  user_profile['interview_in_progress'] = False
75
- bot_msg = "Interview stopped. Type 'feedback' if you'd like me to analyze your answers. Thanks for interviewing with Intervu!"
76
  chat_history.append((message, bot_msg))
77
  return chat_history
78
 
79
  if user_profile.get("interview_in_progress"):
80
  q_index = user_profile['current_q']
81
  user_profile['user_answers'].append(message)
82
-
83
  q_index += 1
84
  user_profile['current_q'] = q_index
85
 
@@ -87,7 +84,7 @@ def respond(message, chat_history, user_profile):
87
  bot_msg = f"Next question: {user_profile['questions'][q_index]['question']}"
88
  else:
89
  user_profile['interview_in_progress'] = False
90
- bot_msg = "Interview complete! Type 'feedback' if you'd like me to analyze your answers. Thanks for interviewing with Intervu!"
91
  chat_history.append((message, bot_msg))
92
  return chat_history
93
 
@@ -96,7 +93,7 @@ def respond(message, chat_history, user_profile):
96
  chat_history.append((message, feedback))
97
  return chat_history
98
 
99
- # starting the chatbot
100
  messages = [{"role": "system", "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in {user_profile['field']}."}]
101
  for q, a in chat_history:
102
  messages.append({"role": "user", "content": q})
@@ -118,98 +115,60 @@ def generate_feedback(user_profile):
118
  if match:
119
  fb = f"Question {i+1}: ✅ Good job!"
120
  else:
121
- fb = f"Question {i+1}: ❌ Missed some key points: {correct_answers[0]}"
122
  feedback.append(fb)
123
  return "\n".join(feedback)
124
 
125
 
126
- # Entire app with CSS styling applied
127
  with gr.Blocks(css="""
128
- body {
129
- background-color: #f2f4f8;
130
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
131
- }
132
- h1, h2, h3 {
133
- text-align: center;
134
- color: #2c3e50;
135
- margin-bottom: 10px;
136
- }
137
- img {
138
- display: block;
139
- margin-left: auto;
140
- margin-right: auto;
141
- border-radius: 15px;
142
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
143
- }
144
- button {
145
- font-size: 16px;
146
- padding: 12px 24px;
147
- background-color: #3B82F6;
148
- color: white;
149
- border: none;
150
- border-radius: 10px;
151
- transition: background-color 0.3s ease;
152
- }
153
- button:hover {
154
- background-color: #2563EB;
155
- }
156
- .gr-chatbot {
157
- background-color: #ffffff;
158
- border-radius: 15px;
159
- padding: 20px;
160
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
161
- max-height: 600px;
162
- overflow-y: auto;
163
- }
164
- textarea {
165
- font-size: 15px;
166
- border-radius: 10px;
167
- padding: 10px;
168
- border: 1px solid #ddd;
169
- }
170
- input[type="text"] {
171
- font-size: 15px;
172
- border-radius: 10px;
173
- padding: 10px;
174
- border: 1px solid #ddd;
175
- }
176
- .gr-textbox {
177
- background-color: #f9fafb;
178
- border-radius: 10px;
179
- padding: 10px;
180
- }
181
  """) as demo:
182
-
183
  user_profile = gr.State({"interview_type": "", "field": "", "interview_in_progress": False})
184
  chat_history = gr.State([])
185
 
186
- gr.Markdown("# Welcome to Intervu")
187
- gr.Markdown('<p align="center"><img src="images.jpeg" width="200"></p>')
 
 
 
 
 
188
 
 
189
  gr.Markdown("### Step 1: Choose Interview Type")
190
  with gr.Row():
191
- with gr.Column():
192
- btn1 = gr.Button("Technical")
193
- btn2 = gr.Button("Competency-Based Interview")
194
- btn3 = gr.Button("Case")
195
- type_output = gr.Textbox(label="Bot response", interactive=False)
196
 
197
  btn1.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
198
  btn2.click(set_type, inputs=[gr.Textbox(value="Competency-Based Interview", visible=False), user_profile], outputs=[type_output, user_profile])
199
  btn3.click(set_type, inputs=[gr.Textbox(value="Case", visible=False), user_profile], outputs=[type_output, user_profile])
200
 
 
201
  gr.Markdown("### Step 2: Enter Your Background")
202
  background = gr.Textbox(label="Your background and field/goal")
203
  background_btn = gr.Button("Submit")
204
  background_output = gr.Textbox(label="Bot response", interactive=False)
205
-
206
  background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
207
 
208
- gr.Markdown("### Step 3: Start Interview")
209
- chatbot = gr.Chatbot(label="Interview Bot")
210
- msg = gr.Textbox(label="Your message")
211
- send_btn = gr.Button("Send")
212
 
 
 
 
 
213
  send_btn.click(respond, inputs=[msg, chat_history, user_profile], outputs=[chatbot], queue=False)
214
  send_btn.click(lambda: "", None, msg, queue=False)
215
 
 
3
  import re
4
  import random
5
 
6
+ # Load questions (your original backend)
7
  def load_questions(file_path):
8
  with open(file_path, 'r') as f:
9
  data = f.read()
 
10
  question_blocks = re.split(r'Question:\s*', data)[1:]
11
  questions = []
12
  for block in question_blocks:
 
19
 
20
  all_questions = load_questions('knowledge.txt')
21
 
22
+ # Question categorization (same as your existing code)
23
  questions_by_type = {
24
  'Technical': [q for q in all_questions if any(keyword in q['question'].lower() for keyword in [
25
  'function', 'linked list', 'url', 'rest', 'graphql', 'garbage', 'cap theorem', 'sql', 'hash table',
 
34
 
35
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
36
 
37
+ # Backend logic (all functions same as before — no changes)
38
  def set_type(choice, user_profile):
39
  user_profile["interview_type"] = choice
40
  return "Great! What’s your background and what field/role are you aiming for?", user_profile
 
51
  chat_history.append((message, bot_msg))
52
  return chat_history
53
 
 
54
  if message_lower == 'start':
55
  interview_type = user_profile['interview_type']
56
  selected_questions = questions_by_type.get(interview_type, [])
 
70
 
71
  if message_lower == 'stop' and user_profile.get("interview_in_progress"):
72
  user_profile['interview_in_progress'] = False
73
+ bot_msg = "Interview stopped. Type 'feedback' if you'd like me to analyze your answers."
74
  chat_history.append((message, bot_msg))
75
  return chat_history
76
 
77
  if user_profile.get("interview_in_progress"):
78
  q_index = user_profile['current_q']
79
  user_profile['user_answers'].append(message)
 
80
  q_index += 1
81
  user_profile['current_q'] = q_index
82
 
 
84
  bot_msg = f"Next question: {user_profile['questions'][q_index]['question']}"
85
  else:
86
  user_profile['interview_in_progress'] = False
87
+ bot_msg = "Interview complete! Type 'feedback' if you'd like me to analyze your answers."
88
  chat_history.append((message, bot_msg))
89
  return chat_history
90
 
 
93
  chat_history.append((message, feedback))
94
  return chat_history
95
 
96
+ # Normal chatbot conversation
97
  messages = [{"role": "system", "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in {user_profile['field']}."}]
98
  for q, a in chat_history:
99
  messages.append({"role": "user", "content": q})
 
115
  if match:
116
  fb = f"Question {i+1}: ✅ Good job!"
117
  else:
118
+ fb = f"Question {i+1}: ❌ Missed key points: {correct_answers[0]}"
119
  feedback.append(fb)
120
  return "\n".join(feedback)
121
 
122
 
123
+ # The new Intervu 2.0 UI with your design!
124
  with gr.Blocks(css="""
125
+ body { background-color: #f2f4f8; font-family: 'Segoe UI', sans-serif; }
126
+ h1 { text-align: center; color: #2c3e50; }
127
+ img { display: block; margin: auto; width: 100px; border-radius: 20px; }
128
+ button { font-size: 16px; padding: 10px 20px; border-radius: 10px; border: none; background-color: #3B82F6; color: white; }
129
+ button:hover { background-color: #2563EB; }
130
+ .gr-chatbot { background-color: white; border-radius: 15px; padding: 20px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  """) as demo:
132
+
133
  user_profile = gr.State({"interview_type": "", "field": "", "interview_in_progress": False})
134
  chat_history = gr.State([])
135
 
136
+ # Header
137
+ gr.Markdown("""
138
+ <div style='text-align:center;'>
139
+ <img src="images/logo.png">
140
+ <h1>Welcome to <b>Intervu</b></h1>
141
+ </div>
142
+ """)
143
 
144
+ # Step 1 - Choose Interview Type
145
  gr.Markdown("### Step 1: Choose Interview Type")
146
  with gr.Row():
147
+ btn1 = gr.Button("Technical")
148
+ btn2 = gr.Button("Competency-Based Interview")
149
+ btn3 = gr.Button("Case")
150
+ type_output = gr.Textbox(label="Bot response", interactive=False)
 
151
 
152
  btn1.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
153
  btn2.click(set_type, inputs=[gr.Textbox(value="Competency-Based Interview", visible=False), user_profile], outputs=[type_output, user_profile])
154
  btn3.click(set_type, inputs=[gr.Textbox(value="Case", visible=False), user_profile], outputs=[type_output, user_profile])
155
 
156
+ # Step 2 - Enter Background
157
  gr.Markdown("### Step 2: Enter Your Background")
158
  background = gr.Textbox(label="Your background and field/goal")
159
  background_btn = gr.Button("Submit")
160
  background_output = gr.Textbox(label="Bot response", interactive=False)
 
161
  background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
162
 
163
+ # Step 3 - Chatbot Mode Selection
164
+ gr.Markdown("### Choose Chat Mode")
165
+ with gr.Row():
166
+ gr.Button("Text-Based") # You can build voice & webcam later :)
167
 
168
+ # Chat interface
169
+ chatbot = gr.Chatbot(label="Interview Chat")
170
+ msg = gr.Textbox(label="Type 'start' to begin")
171
+ send_btn = gr.Button("Send")
172
  send_btn.click(respond, inputs=[msg, chat_history, user_profile], outputs=[chatbot], queue=False)
173
  send_btn.click(lambda: "", None, msg, queue=False)
174