Mahmoud-Dev commited on
Commit
6419b7f
·
verified ·
1 Parent(s): 9d6c04b

Initial: AI Job Interview Bot for Computer Science with 496+ questions

Browse files
Files changed (1) hide show
  1. app.py +182 -0
app.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import json
4
+ from datasets import load_dataset
5
+
6
+ try:
7
+ ds = load_dataset('Aiman1234/Interview-questions')
8
+ questions_data = ds['train']
9
+ except:
10
+ questions_data = None
11
+
12
+ class InterviewBot:
13
+ def __init__(self):
14
+ self.current_question = None
15
+ self.score = 0
16
+ self.total_questions = 0
17
+ self.performance_notes = []
18
+ self.answers_given = []
19
+
20
+ def get_next_question(self, difficulty='Easy'):
21
+ if questions_data is None:
22
+ return "Dataset not available", "N/A", "N/A"
23
+
24
+ filtered = [q for q in questions_data if q['level'] == difficulty]
25
+ if not filtered:
26
+ filtered = questions_data
27
+
28
+ self.current_question = random.choice(filtered)
29
+ self.total_questions += 1
30
+
31
+ return (
32
+ self.current_question['Questions'],
33
+ self.current_question['language'],
34
+ self.current_question['level']
35
+ )
36
+
37
+ def evaluate_answer(self, user_answer):
38
+ if not self.current_question:
39
+ return "Please get a question first!"
40
+
41
+ answer_length = len(user_answer.split())
42
+ correct_answer_length = len(self.current_question['Answers'].split())
43
+
44
+ similarity = min(answer_length, correct_answer_length) / max(answer_length, correct_answer_length) if max(answer_length, correct_answer_length) > 0 else 0
45
+
46
+ if similarity > 0.5:
47
+ feedback = f"Good effort! Your answer covers key points.\nExpected answer length: ~{correct_answer_length} words, Your answer: {answer_length} words"
48
+ self.score += 1
49
+ else:
50
+ feedback = f"Consider expanding your answer. Your response should be more detailed.\nExpected length: ~{correct_answer_length} words, Your answer: {answer_length} words"
51
+
52
+ self.answers_given.append({
53
+ 'question': self.current_question['Questions'],
54
+ 'your_answer': user_answer,
55
+ 'similarity': similarity,
56
+ 'correct_answer': self.current_question['Answers']
57
+ })
58
+
59
+ return feedback
60
+
61
+ def get_performance_analysis(self):
62
+ if self.total_questions == 0:
63
+ return "No questions answered yet!"
64
+
65
+ accuracy = (self.score / self.total_questions) * 100
66
+
67
+ analysis = f"""
68
+ === PERFORMANCE ANALYSIS ===
69
+
70
+ Total Questions: {self.total_questions}
71
+ Correct Answers: {self.score}
72
+ Accuracy: {accuracy:.1f}%
73
+
74
+ STRENGTHS:
75
+ - You completed {self.total_questions} interview questions
76
+ - Your accuracy rate is {accuracy:.1f}%
77
+
78
+ AREAS FOR IMPROVEMENT:
79
+ - Focus on providing detailed and structured answers
80
+ - Practice technical concepts and definitions
81
+ - Improve answer articulation and clarity
82
+
83
+ RECOMMENDATIONS:
84
+ 1. Review the expected answers for failed questions
85
+ 2. Practice similar questions in your weak areas
86
+ 3. Work on concise but comprehensive responses
87
+ 4. Practice explaining complex concepts simply
88
+ """
89
+
90
+ return analysis
91
+
92
+ bot = InterviewBot()
93
+
94
+ def start_interview(difficulty):
95
+ question, language, level = bot.get_next_question(difficulty)
96
+ return f"Question ({language} - {level}): {question}"
97
+
98
+ def submit_answer(answer_text):
99
+ if not answer_text.strip():
100
+ return "Please provide an answer!"
101
+ evaluation = bot.evaluate_answer(answer_text)
102
+ return evaluation
103
+
104
+ def show_analysis():
105
+ return bot.get_performance_analysis()
106
+
107
+ with gr.Blocks(title="AI Job Interview Bot - Computer Science") as demo:
108
+ gr.Markdown("""
109
+ # AI Job Interview Bot for Computer Science
110
+
111
+ Practice technical interview questions with AI-powered feedback!
112
+
113
+ **Features:**
114
+ - 496+ real interview questions
115
+ - Multiple difficulty levels
116
+ - Performance analysis and feedback
117
+ - Identified strengths and weaknesses
118
+ """)
119
+
120
+ with gr.Row():
121
+ with gr.Column():
122
+ gr.Markdown("### Interview Settings")
123
+ difficulty = gr.Radio(
124
+ choices=['Easy', 'Medium', 'Hard'],
125
+ value='Easy',
126
+ label="Select Difficulty Level"
127
+ )
128
+ start_btn = gr.Button("Get Next Question", variant="primary")
129
+
130
+ with gr.Column():
131
+ gr.Markdown("### Current Question")
132
+ question_display = gr.Textbox(
133
+ label="Question",
134
+ interactive=False,
135
+ lines=4
136
+ )
137
+
138
+ with gr.Row():
139
+ with gr.Column():
140
+ gr.Markdown("### Your Answer")
141
+ answer_input = gr.Textbox(
142
+ label="Type your answer here",
143
+ lines=6,
144
+ placeholder="Provide your answer to the question..."
145
+ )
146
+ submit_btn = gr.Button("Submit Answer", variant="primary")
147
+
148
+ with gr.Column():
149
+ gr.Markdown("### AI Feedback")
150
+ feedback_display = gr.Textbox(
151
+ label="Feedback",
152
+ interactive=False,
153
+ lines=6
154
+ )
155
+
156
+ with gr.Row():
157
+ analysis_btn = gr.Button("Show Performance Analysis", variant="secondary")
158
+ analysis_display = gr.Textbox(
159
+ label="Performance Analysis",
160
+ interactive=False,
161
+ lines=15
162
+ )
163
+
164
+ start_btn.click(
165
+ fn=start_interview,
166
+ inputs=[difficulty],
167
+ outputs=[question_display]
168
+ )
169
+
170
+ submit_btn.click(
171
+ fn=submit_answer,
172
+ inputs=[answer_input],
173
+ outputs=[feedback_display]
174
+ )
175
+
176
+ analysis_btn.click(
177
+ fn=show_analysis,
178
+ outputs=[analysis_display]
179
+ )
180
+
181
+ if __name__ == "__main__":
182
+ demo.launch()