Spaces:
Sleeping
Sleeping
Fix: Remove size parameter and improve error handling for dataset loading
Browse files
app.py
CHANGED
|
@@ -1,120 +1,135 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
-
import json
|
| 4 |
from datasets import load_dataset
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
questions_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 22 |
-
return "
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
|
| 37 |
def evaluate_answer(self, user_answer):
|
| 38 |
if not self.current_question:
|
| 39 |
return "Please get a question first!"
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
def get_performance_analysis(self):
|
| 62 |
if self.total_questions == 0:
|
| 63 |
return "No questions answered yet!"
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
bot = InterviewBot()
|
| 93 |
|
| 94 |
def start_interview(difficulty):
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
def submit_answer(answer_text):
|
| 99 |
if not answer_text.strip():
|
| 100 |
return "Please provide an answer!"
|
| 101 |
-
|
| 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 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
""")
|
| 119 |
|
| 120 |
with gr.Row():
|
|
@@ -132,7 +147,7 @@ with gr.Blocks(title="AI Job Interview Bot - Computer Science") as demo:
|
|
| 132 |
question_display = gr.Textbox(
|
| 133 |
label="Question",
|
| 134 |
interactive=False,
|
| 135 |
-
lines=
|
| 136 |
)
|
| 137 |
|
| 138 |
with gr.Row():
|
|
@@ -155,11 +170,12 @@ with gr.Blocks(title="AI Job Interview Bot - Computer Science") as demo:
|
|
| 155 |
|
| 156 |
with gr.Row():
|
| 157 |
analysis_btn = gr.Button("Show Performance Analysis", variant="secondary")
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 163 |
|
| 164 |
start_btn.click(
|
| 165 |
fn=start_interview,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
from datasets import load_dataset
|
| 4 |
|
| 5 |
+
questions_data = None
|
| 6 |
+
|
| 7 |
+
def load_questions():
|
| 8 |
+
global questions_data
|
| 9 |
+
if questions_data is None:
|
| 10 |
+
try:
|
| 11 |
+
ds = load_dataset('Aiman1234/Interview-questions')
|
| 12 |
+
questions_data = ds['train']
|
| 13 |
+
return True
|
| 14 |
+
except Exception as e:
|
| 15 |
+
print(f"Error loading dataset: {e}")
|
| 16 |
+
return False
|
| 17 |
+
return True
|
| 18 |
|
| 19 |
class InterviewBot:
|
| 20 |
def __init__(self):
|
| 21 |
self.current_question = None
|
| 22 |
self.score = 0
|
| 23 |
self.total_questions = 0
|
|
|
|
| 24 |
self.answers_given = []
|
| 25 |
|
| 26 |
def get_next_question(self, difficulty='Easy'):
|
| 27 |
+
if not load_questions():
|
| 28 |
+
return "Failed to load questions. Please try again.", "N/A", "N/A"
|
| 29 |
|
| 30 |
+
try:
|
| 31 |
+
filtered = [q for q in questions_data if q['level'] == difficulty]
|
| 32 |
+
if not filtered:
|
| 33 |
+
filtered = list(questions_data)
|
| 34 |
+
|
| 35 |
+
self.current_question = random.choice(filtered)
|
| 36 |
+
self.total_questions += 1
|
| 37 |
|
| 38 |
+
return (
|
| 39 |
+
self.current_question['Questions'],
|
| 40 |
+
self.current_question['language'],
|
| 41 |
+
self.current_question['level']
|
| 42 |
+
)
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error getting question: {str(e)}", "Error", "Error"
|
|
|
|
| 45 |
|
| 46 |
def evaluate_answer(self, user_answer):
|
| 47 |
if not self.current_question:
|
| 48 |
return "Please get a question first!"
|
| 49 |
|
| 50 |
+
try:
|
| 51 |
+
answer_length = len(user_answer.split())
|
| 52 |
+
correct_answer_length = len(self.current_question['Answers'].split())
|
| 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 |
+
|
| 56 |
+
if similarity > 0.5:
|
| 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. Your response should be more detailed.\nExpected length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
|
| 61 |
+
|
| 62 |
+
self.answers_given.append({
|
| 63 |
+
'question': self.current_question['Questions'],
|
| 64 |
+
'your_answer': user_answer,
|
| 65 |
+
'similarity': similarity
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
return feedback
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"Error evaluating answer: {str(e)}"
|
| 71 |
|
| 72 |
def get_performance_analysis(self):
|
| 73 |
if self.total_questions == 0:
|
| 74 |
return "No questions answered yet!"
|
| 75 |
|
| 76 |
+
try:
|
| 77 |
+
accuracy = (self.score / self.total_questions) * 100
|
| 78 |
+
|
| 79 |
+
analysis = f"""
|
| 80 |
+
PERFORMANCE ANALYSIS
|
| 81 |
+
{'='*50}
|
| 82 |
+
Total Questions Attempted: {self.total_questions}
|
| 83 |
+
Correct Answers: {self.score}
|
| 84 |
+
Accuracy Rate: {accuracy:.1f}%
|
| 85 |
+
|
| 86 |
+
STRENGTHS:
|
| 87 |
+
- Successfully completed {self.total_questions} interview questions
|
| 88 |
+
- Current accuracy rate: {accuracy:.1f}%
|
| 89 |
+
|
| 90 |
+
AREAS FOR IMPROVEMENT:
|
| 91 |
+
- Focus on providing detailed and structured answers
|
| 92 |
+
- Practice technical concepts and definitions
|
| 93 |
+
- Improve answer clarity and completeness
|
| 94 |
+
|
| 95 |
+
RECOMMENDATIONS:
|
| 96 |
+
1. Review the expected answers for failed questions
|
| 97 |
+
2. Practice similar questions in weak areas
|
| 98 |
+
3. Work on concise but comprehensive responses
|
| 99 |
+
4. Practice explaining complex concepts clearly
|
| 100 |
+
"""
|
| 101 |
+
return analysis
|
| 102 |
+
except Exception as e:
|
| 103 |
+
return f"Error generating analysis: {str(e)}"
|
| 104 |
|
| 105 |
bot = InterviewBot()
|
| 106 |
|
| 107 |
def start_interview(difficulty):
|
| 108 |
+
try:
|
| 109 |
+
question, language, level = bot.get_next_question(difficulty)
|
| 110 |
+
return f"Question ({language} - {level}):\n{question}"
|
| 111 |
+
except Exception as e:
|
| 112 |
+
return f"Error: {str(e)}"
|
| 113 |
|
| 114 |
def submit_answer(answer_text):
|
| 115 |
if not answer_text.strip():
|
| 116 |
return "Please provide an answer!"
|
| 117 |
+
return bot.evaluate_answer(answer_text)
|
|
|
|
| 118 |
|
| 119 |
def show_analysis():
|
| 120 |
return bot.get_performance_analysis()
|
| 121 |
|
| 122 |
with gr.Blocks(title="AI Job Interview Bot - Computer Science") as demo:
|
| 123 |
gr.Markdown("""
|
| 124 |
+
# AI Job Interview Bot for Computer Science
|
| 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():
|
|
|
|
| 147 |
question_display = gr.Textbox(
|
| 148 |
label="Question",
|
| 149 |
interactive=False,
|
| 150 |
+
lines=5
|
| 151 |
)
|
| 152 |
|
| 153 |
with gr.Row():
|
|
|
|
| 170 |
|
| 171 |
with gr.Row():
|
| 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=15
|
| 178 |
+
)
|
| 179 |
|
| 180 |
start_btn.click(
|
| 181 |
fn=start_interview,
|