Spaces:
Running
Running
Fix: Handle missing 'level' field with .get() method and improve error handling
Browse files
app.py
CHANGED
|
@@ -28,17 +28,19 @@ class InterviewBot:
|
|
| 28 |
return "Failed to load questions. Please try again.", "N/A", "N/A"
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
filtered =
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
self.current_question = random.choice(filtered)
|
| 36 |
self.total_questions += 1
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return (
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
)
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error getting question: {str(e)}", "Error", "Error"
|
|
@@ -49,7 +51,8 @@ class InterviewBot:
|
|
| 49 |
|
| 50 |
try:
|
| 51 |
answer_length = len(user_answer.split())
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
similarity = min(answer_length, correct_answer_length) / max(answer_length, correct_answer_length) if max(answer_length, correct_answer_length) > 0 else 0
|
| 55 |
|
|
@@ -57,10 +60,10 @@ class InterviewBot:
|
|
| 57 |
feedback = f"Good effort! Your answer covers key points.\nExpected answer length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
|
| 58 |
self.score += 1
|
| 59 |
else:
|
| 60 |
-
feedback = f"Consider expanding your answer
|
| 61 |
|
| 62 |
self.answers_given.append({
|
| 63 |
-
'question': self.current_question
|
| 64 |
'your_answer': user_answer,
|
| 65 |
'similarity': similarity
|
| 66 |
})
|
|
@@ -88,15 +91,15 @@ STRENGTHS:
|
|
| 88 |
- Current accuracy rate: {accuracy:.1f}%
|
| 89 |
|
| 90 |
AREAS FOR IMPROVEMENT:
|
| 91 |
-
- Focus on providing detailed
|
| 92 |
-
- Practice technical concepts
|
| 93 |
-
- Improve
|
| 94 |
|
| 95 |
RECOMMENDATIONS:
|
| 96 |
-
1. Review
|
| 97 |
-
2. Practice similar questions
|
| 98 |
-
3. Work on
|
| 99 |
-
4.
|
| 100 |
"""
|
| 101 |
return analysis
|
| 102 |
except Exception as e:
|
|
@@ -107,7 +110,7 @@ bot = InterviewBot()
|
|
| 107 |
def start_interview(difficulty):
|
| 108 |
try:
|
| 109 |
question, language, level = bot.get_next_question(difficulty)
|
| 110 |
-
return f"
|
| 111 |
except Exception as e:
|
| 112 |
return f"Error: {str(e)}"
|
| 113 |
|
|
@@ -119,31 +122,22 @@ def submit_answer(answer_text):
|
|
| 119 |
def show_analysis():
|
| 120 |
return bot.get_performance_analysis()
|
| 121 |
|
| 122 |
-
with gr.Blocks(title="AI
|
| 123 |
-
gr.Markdown(""
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
Practice technical interview questions with AI-powered feedback!
|
| 127 |
-
|
| 128 |
-
**Features:**
|
| 129 |
-
- 496+ real interview questions
|
| 130 |
-
- Multiple difficulty levels (Easy, Medium, Hard)
|
| 131 |
-
- Real-time AI feedback on your answers
|
| 132 |
-
- Performance analysis and recommendations
|
| 133 |
-
""")
|
| 134 |
|
| 135 |
with gr.Row():
|
| 136 |
with gr.Column():
|
| 137 |
-
gr.Markdown("###
|
| 138 |
difficulty = gr.Radio(
|
| 139 |
choices=['Easy', 'Medium', 'Hard'],
|
| 140 |
value='Easy',
|
| 141 |
-
label="
|
| 142 |
)
|
| 143 |
start_btn = gr.Button("Get Next Question", variant="primary")
|
| 144 |
|
| 145 |
with gr.Column():
|
| 146 |
-
gr.Markdown("###
|
| 147 |
question_display = gr.Textbox(
|
| 148 |
label="Question",
|
| 149 |
interactive=False,
|
|
@@ -154,27 +148,22 @@ Practice technical interview questions with AI-powered feedback!
|
|
| 154 |
with gr.Column():
|
| 155 |
gr.Markdown("### Your Answer")
|
| 156 |
answer_input = gr.Textbox(
|
| 157 |
-
label="Type your answer here",
|
| 158 |
lines=6,
|
| 159 |
-
placeholder="
|
| 160 |
)
|
| 161 |
submit_btn = gr.Button("Submit Answer", variant="primary")
|
| 162 |
|
| 163 |
with gr.Column():
|
| 164 |
-
gr.Markdown("###
|
| 165 |
feedback_display = gr.Textbox(
|
| 166 |
-
label="Feedback",
|
| 167 |
interactive=False,
|
| 168 |
lines=6
|
| 169 |
)
|
| 170 |
|
| 171 |
-
|
| 172 |
-
analysis_btn = gr.Button("Show Performance Analysis", variant="secondary")
|
| 173 |
-
|
| 174 |
analysis_display = gr.Textbox(
|
| 175 |
-
label="Performance Analysis",
|
| 176 |
interactive=False,
|
| 177 |
-
lines=
|
| 178 |
)
|
| 179 |
|
| 180 |
start_btn.click(
|
|
|
|
| 28 |
return "Failed to load questions. Please try again.", "N/A", "N/A"
|
| 29 |
|
| 30 |
try:
|
| 31 |
+
filtered = list(questions_data)
|
| 32 |
+
random_q = random.choice(filtered)
|
| 33 |
+
self.current_question = random_q
|
|
|
|
|
|
|
| 34 |
self.total_questions += 1
|
| 35 |
|
| 36 |
+
lang = random_q.get('language', 'Unknown')
|
| 37 |
+
level = random_q.get('level', 'Not specified')
|
| 38 |
+
question = random_q.get('Questions', 'No question')
|
| 39 |
+
|
| 40 |
return (
|
| 41 |
+
f"{question}",
|
| 42 |
+
str(lang),
|
| 43 |
+
str(level)
|
| 44 |
)
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error getting question: {str(e)}", "Error", "Error"
|
|
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
answer_length = len(user_answer.split())
|
| 54 |
+
correct_answer = self.current_question.get('Answers', '')
|
| 55 |
+
correct_answer_length = len(correct_answer.split())
|
| 56 |
|
| 57 |
similarity = min(answer_length, correct_answer_length) / max(answer_length, correct_answer_length) if max(answer_length, correct_answer_length) > 0 else 0
|
| 58 |
|
|
|
|
| 60 |
feedback = f"Good effort! Your answer covers key points.\nExpected answer length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
|
| 61 |
self.score += 1
|
| 62 |
else:
|
| 63 |
+
feedback = f"Consider expanding your answer.\nExpected length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
|
| 64 |
|
| 65 |
self.answers_given.append({
|
| 66 |
+
'question': self.current_question.get('Questions', ''),
|
| 67 |
'your_answer': user_answer,
|
| 68 |
'similarity': similarity
|
| 69 |
})
|
|
|
|
| 91 |
- Current accuracy rate: {accuracy:.1f}%
|
| 92 |
|
| 93 |
AREAS FOR IMPROVEMENT:
|
| 94 |
+
- Focus on providing detailed answers
|
| 95 |
+
- Practice technical concepts
|
| 96 |
+
- Improve clarity in explanations
|
| 97 |
|
| 98 |
RECOMMENDATIONS:
|
| 99 |
+
1. Review expected answers for questions
|
| 100 |
+
2. Practice similar questions
|
| 101 |
+
3. Work on comprehensive responses
|
| 102 |
+
4. Explain concepts clearly
|
| 103 |
"""
|
| 104 |
return analysis
|
| 105 |
except Exception as e:
|
|
|
|
| 110 |
def start_interview(difficulty):
|
| 111 |
try:
|
| 112 |
question, language, level = bot.get_next_question(difficulty)
|
| 113 |
+
return f"{question}\n\n(Language: {language} | Level: {level})"
|
| 114 |
except Exception as e:
|
| 115 |
return f"Error: {str(e)}"
|
| 116 |
|
|
|
|
| 122 |
def show_analysis():
|
| 123 |
return bot.get_performance_analysis()
|
| 124 |
|
| 125 |
+
with gr.Blocks(title="AI Interview Bot CS") as demo:
|
| 126 |
+
gr.Markdown("# AI Job Interview Bot - Computer Science")
|
| 127 |
+
gr.Markdown("Practice 496+ technical interview questions with AI feedback")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
with gr.Row():
|
| 130 |
with gr.Column():
|
| 131 |
+
gr.Markdown("### Settings")
|
| 132 |
difficulty = gr.Radio(
|
| 133 |
choices=['Easy', 'Medium', 'Hard'],
|
| 134 |
value='Easy',
|
| 135 |
+
label="Difficulty"
|
| 136 |
)
|
| 137 |
start_btn = gr.Button("Get Next Question", variant="primary")
|
| 138 |
|
| 139 |
with gr.Column():
|
| 140 |
+
gr.Markdown("### Question")
|
| 141 |
question_display = gr.Textbox(
|
| 142 |
label="Question",
|
| 143 |
interactive=False,
|
|
|
|
| 148 |
with gr.Column():
|
| 149 |
gr.Markdown("### Your Answer")
|
| 150 |
answer_input = gr.Textbox(
|
|
|
|
| 151 |
lines=6,
|
| 152 |
+
placeholder="Your answer..."
|
| 153 |
)
|
| 154 |
submit_btn = gr.Button("Submit Answer", variant="primary")
|
| 155 |
|
| 156 |
with gr.Column():
|
| 157 |
+
gr.Markdown("### Feedback")
|
| 158 |
feedback_display = gr.Textbox(
|
|
|
|
| 159 |
interactive=False,
|
| 160 |
lines=6
|
| 161 |
)
|
| 162 |
|
| 163 |
+
analysis_btn = gr.Button("Performance Analysis", variant="secondary")
|
|
|
|
|
|
|
| 164 |
analysis_display = gr.Textbox(
|
|
|
|
| 165 |
interactive=False,
|
| 166 |
+
lines=12
|
| 167 |
)
|
| 168 |
|
| 169 |
start_btn.click(
|