Spaces:
Sleeping
Sleeping
Initial: AI Job Interview Bot for Computer Science with 496+ questions
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182import gradio as grimport randomimport jsonfrom datasets import load_dataset
try: ds = load_dataset('Aiman1234/Interview-questions') questions_data = ds['train']except: questions_data = None
class InterviewBot: def __init__(self): self.current_question = None self.score = 0 self.total_questions = 0 self.performance_notes = [] self.answers_given = [] def get_next_question(self, difficulty='Easy'): if questions_data is None: return "Dataset not available", "N/A", "N/A" filtered = [q for q in questions_data if q['level'] == difficulty] if not filtered: filtered = questions_data self.current_question = random.choice(filtered) self.total_questions += 1 return ( self.current_question['Questions'], self.current_question['language'], self.current_question['level'] ) def evaluate_answer(self, user_answer): if not self.current_question: return "Please get a question first!" answer_length = len(user_answer.split()) correct_answer_length = len(self.current_question['Answers'].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, Your answer: {answer_length} words" self.score += 1 else: feedback = f"Consider expanding your answer. Your response should be more detailed.\nExpected length: ~{correct_answer_length} words, Your answer: {answer_length} words" self.answers_given.append({ 'question': self.current_question['Questions'], 'your_answer': user_answer, 'similarity': similarity, 'correct_answer': self.current_question['Answers'] }) return feedback def get_performance_analysis(self): if self.total_questions == 0: return "No questions answered yet!" accuracy = (self.score / self.total_questions) * 100 analysis = f""" === PERFORMANCE ANALYSIS === Total Questions: {self.total_questions} Correct Answers: {self.score} Accuracy: {accuracy:.1f}% STRENGTHS: - You completed {self.total_questions} interview questions - Your accuracy rate is {accuracy:.1f}% AREAS FOR IMPROVEMENT: - Focus on providing detailed and structured answers - Practice technical concepts and definitions - Improve answer articulation and clarity RECOMMENDATIONS: 1. Review the expected answers for failed questions 2. Practice similar questions in your weak areas 3. Work on concise but comprehensive responses 4. Practice explaining complex concepts simply """ return analysis
bot = InterviewBot()
def start_interview(difficulty): question, language, level = bot.get_next_question(difficulty) return f"Question ({language} - {level}): {question}"
def submit_answer(answer_text): if not answer_text.strip(): return "Please provide an answer!" evaluation = bot.evaluate_answer(answer_text) return evaluation
def show_analysis(): return bot.get_performance_analysis()
with gr.Blocks(title="AI Job Interview Bot - Computer Science") as demo: gr.Markdown(""" # AI Job Interview Bot for Computer Science Practice technical interview questions with AI-powered feedback! **Features:** - 496+ real interview questions - Multiple difficulty levels - Performance analysis and feedback - Identified strengths and weaknesses """) with gr.Row(): with gr.Column(): gr.Markdown("### Interview Settings") difficulty = gr.Radio( choices=['Easy', 'Medium', 'Hard'], value='Easy', label="Select Difficulty Level" ) start_btn = gr.Button("Get Next Question", variant="primary") with gr.Column(): gr.Markdown("### Current Question") question_display = gr.Textbox( label="Question", interactive=False, lines=4 ) with gr.Row(): with gr.Column(): gr.Markdown("### Your Answer") answer_input = gr.Textbox( label="Type your answer here", lines=6, placeholder="Provide your answer to the question..." ) submit_btn = gr.Button("Submit Answer", variant="primary") with gr.Column(): gr.Markdown("### AI Feedback") feedback_display = gr.Textbox( label="Feedback", interactive=False, lines=6 ) with gr.Row(): analysis_btn = gr.Button("Show Performance Analysis", variant="secondary") analysis_display = gr.Textbox( label="Performance Analysis", interactive=False, lines=15 ) 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()app.pyAdded+182