Spaces:
Sleeping
Sleeping
File size: 5,882 Bytes
6419b7f 2025989 6419b7f 2025989 6419b7f 2025989 820f8ca 2025989 6419b7f 820f8ca 2025989 820f8ca 2025989 6419b7f 2025989 820f8ca 2025989 820f8ca 2025989 820f8ca 2025989 6419b7f 2025989 820f8ca 2025989 820f8ca 2025989 6419b7f 2025989 820f8ca 2025989 6419b7f 2025989 6419b7f 820f8ca 6419b7f 820f8ca 6419b7f 820f8ca 6419b7f 820f8ca 6419b7f 2025989 6419b7f 820f8ca 6419b7f 820f8ca 6419b7f 820f8ca 2025989 820f8ca 2025989 6419b7f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
import gradio as gr
import random
from datasets import load_dataset
questions_data = None
def load_questions():
global questions_data
if questions_data is None:
try:
ds = load_dataset('Aiman1234/Interview-questions')
questions_data = ds['train']
return True
except Exception as e:
print(f"Error loading dataset: {e}")
return False
return True
class InterviewBot:
def __init__(self):
self.current_question = None
self.score = 0
self.total_questions = 0
self.answers_given = []
def get_next_question(self, difficulty='Easy'):
if not load_questions():
return "Failed to load questions. Please try again.", "N/A", "N/A"
try:
filtered = list(questions_data)
random_q = random.choice(filtered)
self.current_question = random_q
self.total_questions += 1
lang = random_q.get('language', 'Unknown')
level = random_q.get('level', 'Not specified')
question = random_q.get('Questions', 'No question')
return (
f"{question}",
str(lang),
str(level)
)
except Exception as e:
return f"Error getting question: {str(e)}", "Error", "Error"
def evaluate_answer(self, user_answer):
if not self.current_question:
return "Please get a question first!"
try:
answer_length = len(user_answer.split())
correct_answer = self.current_question.get('Answers', '')
correct_answer_length = len(correct_answer.split())
similarity = min(answer_length, correct_answer_length) / max(answer_length, correct_answer_length) if max(answer_length, correct_answer_length) > 0 else 0
if similarity > 0.5:
feedback = f"Good effort! Your answer covers key points.\nExpected answer length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
self.score += 1
else:
feedback = f"Consider expanding your answer.\nExpected length: ~{correct_answer_length} words\nYour answer: {answer_length} words"
self.answers_given.append({
'question': self.current_question.get('Questions', ''),
'your_answer': user_answer,
'similarity': similarity
})
return feedback
except Exception as e:
return f"Error evaluating answer: {str(e)}"
def get_performance_analysis(self):
if self.total_questions == 0:
return "No questions answered yet!"
try:
accuracy = (self.score / self.total_questions) * 100
analysis = f"""
PERFORMANCE ANALYSIS
{'='*50}
Total Questions Attempted: {self.total_questions}
Correct Answers: {self.score}
Accuracy Rate: {accuracy:.1f}%
STRENGTHS:
- Successfully completed {self.total_questions} interview questions
- Current accuracy rate: {accuracy:.1f}%
AREAS FOR IMPROVEMENT:
- Focus on providing detailed answers
- Practice technical concepts
- Improve clarity in explanations
RECOMMENDATIONS:
1. Review expected answers for questions
2. Practice similar questions
3. Work on comprehensive responses
4. Explain concepts clearly
"""
return analysis
except Exception as e:
return f"Error generating analysis: {str(e)}"
bot = InterviewBot()
def start_interview(difficulty):
try:
question, language, level = bot.get_next_question(difficulty)
return f"{question}\n\n(Language: {language} | Level: {level})"
except Exception as e:
return f"Error: {str(e)}"
def submit_answer(answer_text):
if not answer_text.strip():
return "Please provide an answer!"
return bot.evaluate_answer(answer_text)
def show_analysis():
return bot.get_performance_analysis()
with gr.Blocks(title="AI Interview Bot CS") as demo:
gr.Markdown("# AI Job Interview Bot - Computer Science")
gr.Markdown("Practice 496+ technical interview questions with AI feedback")
with gr.Row():
with gr.Column():
gr.Markdown("### Settings")
difficulty = gr.Radio(
choices=['Easy', 'Medium', 'Hard'],
value='Easy',
label="Difficulty"
)
start_btn = gr.Button("Get Next Question", variant="primary")
with gr.Column():
gr.Markdown("### Question")
question_display = gr.Textbox(
label="Question",
interactive=False,
lines=5
)
with gr.Row():
with gr.Column():
gr.Markdown("### Your Answer")
answer_input = gr.Textbox(
lines=6,
placeholder="Your answer..."
)
submit_btn = gr.Button("Submit Answer", variant="primary")
with gr.Column():
gr.Markdown("### Feedback")
feedback_display = gr.Textbox(
interactive=False,
lines=6
)
analysis_btn = gr.Button("Performance Analysis", variant="secondary")
analysis_display = gr.Textbox(
interactive=False,
lines=12
)
start_btn.click(
fn=start_interview,
inputs=[difficulty],
outputs=[question_display]
)
submit_btn.click(
fn=submit_answer,
inputs=[answer_input],
outputs=[feedback_display]
)
analysis_btn.click(
fn=show_analysis,
outputs=[analysis_display]
)
if __name__ == "__main__":
demo.launch() |