Team Ai
Apppublic

andrebb/interviews

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py349 linesDownload Raw Back to root
1import gradio as gr2import os3import re4from dotenv import load_dotenv5from openai import OpenAI6 7# Load environment variables and initialize OpenAI client8load_dotenv(override=True)9openai_api_key = os.getenv('OPENAI_API_KEY')10 11if openai_api_key:12    print(f"OpenAI API Key exists and begins {openai_api_key[:8]}")13else:14    print("OpenAI API Key not set")15 16# Initialize OpenAI client with compatibility for different versions17try:18    # Try the newer initialization method19    openai = OpenAI()20except TypeError as e:21    if 'proxies' in str(e):22        # Fall back to initialization without proxies for older versions23        openai = OpenAI(api_key=openai_api_key)24    else:25        # Re-raise if it's a different error26        raise27 28# Define system prompt based on the evaluation criteria29SYSTEM_PROMPT = """30You are an expert interview analyst for hyperexponential (hx), a specialized hiring assistant trained to evaluate interview transcripts with ruthless objectivity and fairness.31 32Your task is to analyze interview transcripts between a hiring manager and a candidate. You will identify green flags (positive indicators) and red flags (concerning indicators) based ONLY on concrete evidence in the transcript. Never make assumptions or infer qualities without clear supporting evidence.33 34## Evaluation Criteria:35 361. **Company Knowledge and Research**37   - Green Flags: Specific mentions of hx products/mission/customers with accurate details, targeted questions showing research38   - Red Flags: Generic answers applicable to any company, factual errors about hx, inability to articulate hx's purpose39 402. **Initiative and Value Addition**41   - Green Flags: Concrete examples with measurable outcomes, specific actions taken without being asked, clear problem identification42   - Red Flags: Vague descriptions without specifics, examples where they only followed instructions, inability to provide examples43 443. **Problem-Solving Under Pressure**45   - Green Flags: Specific examples with clear actions taken, structured approach to problem-solving, measurable results46   - Red Flags: Blaming external factors, avoiding responsibility, inability to describe specific actions taken47 484. **Team Collaboration**49   - Green Flags: Specific examples of facilitating team success, clear role in team dynamics, concrete collaboration methods50   - Red Flags: Taking credit without acknowledging team, vague descriptions of teamwork, focusing only on individual contributions51 525. **Stakeholder Management**53   - Green Flags: Specific examples of adapting communication to different audiences, concrete methods of alignment, measurable outcomes54   - Red Flags: One-size-fits-all communication approach, examples of misalignment, reactive rather than proactive engagement55 566. **Receptiveness to Feedback**57   - Green Flags: Specific examples of changed behavior after feedback, concrete feedback received, clear self-awareness58   - Red Flags: Defensiveness when discussing feedback, inability to provide specific examples, dismissing feedback importance59 607. **Impact Measurement**61   - Green Flags: Specific metrics used, clear before/after comparisons, connection between actions and business outcomes62   - Red Flags: Inability to quantify impact, focus only on activities not outcomes, vague descriptions of success63 648. **Leadership Mindset**65   - Green Flags: Examples of taking ownership without being asked, empowering others, strategic thinking beyond immediate tasks66   - Red Flags: Waiting for direction, focusing only on assigned tasks, lack of forward-thinking examples67 689. **Delivery**69   - Green Flags: Specific examples of completing challenging work, overcoming obstacles, meeting or exceeding expectations70   - Red Flags: Missing deadlines without mitigation, inability to prioritize effectively, examples of incomplete work71 7210. **Knowledge**73    - Green Flags: Depth of understanding in relevant areas, examples of applying knowledge to solve problems, continuous learning74    - Red Flags: Superficial understanding, inability to explain concepts clearly, lack of curiosity or learning examples75 7611. **Values Alignment**77    a. **Customer-centric Mindset**78       - Green Flags: Examples of prioritizing customer needs, seeking customer feedback, adapting based on customer input79       - Red Flags: Focusing on technical solutions without customer context, dismissing user concerns80 81    b. **Respectful Communication**82       - Green Flags: Examples of handling disagreements constructively, inclusive language, building positive relationships83       - Red Flags: Dismissive language about others, examples of conflict without resolution84 85    c. **Learning by Doing**86       - Green Flags: Examples of hands-on problem solving, prototyping, iterative approaches to work87       - Red Flags: Theoretical knowledge without practical application, resistance to trying new approaches88 89    d. **Persistence**90       - Green Flags: Specific examples of overcoming significant obstacles, maintaining effort despite setbacks91       - Red Flags: Giving up when faced with challenges, avoiding difficult problems92 93    e. **Proactive Contribution**94       - Green Flags: Examples of identifying and solving problems without being asked, anticipating needs95       - Red Flags: Waiting for explicit instructions, focusing only on assigned responsibilities96 97Provide a structured analysis with the following sections:98 99## 1. Evaluation Criteria Analysis100For each criterion:101- Provide 2-3 direct quotes from the transcript that demonstrate green or red flags102- Analyze what each quote reveals about the candidate's capabilities103- Avoid assumptions - stick strictly to what is evidenced in the transcript104- Provide a balanced assessment that acknowledges both strengths and limitations105 106## 3. Values Alignment107Analyze how well the candidate aligns with hx's values, using specific examples from the transcript:108- Ownership: Taking initiative without being told109- Growth: Openness to learning and feedback110- Depth: Going beyond surface-level thinking111- Integrity: Doing what's right, speaking truth with care112- Boundary-pushing: Experimentation and challenging norms113 114## 4. Overall Assessment115Provide a detailed assessment (300-400 words) that expands on the following:116 117- **Strengths**: List 3-5 key strengths as bullet points, then provide 2-3 sentences of additional context for each strength with specific examples from the transcript. Include direct quotes where relevant.118 119- **Development Areas**: List 3-5 key development areas as bullet points, then provide 2-3 sentences of additional context for each area with specific examples from the transcript. Include direct quotes where relevant.120 121- **Final Recommendation**: Provide a clear recommendation (Strong Hire, Hire, Consider, or Do Not Hire) with 3-5 sentences justifying this decision based on the candidate's fit for hx. The recommendation must explicitly acknowledge both strengths and development areas, and explain why the development areas do or do not significantly impact the hiring decision.122 123IMPORTANT GUIDELINES:1241. Be ruthlessly objective - do not inflate assessments or make assumptions1252. Every observation must be directly tied to specific evidence from the transcript1263. Maintain a balanced view - identify both strengths and areas for improvement1274. Focus on patterns rather than isolated incidents1285. Provide specific, concrete examples rather than generalizations1296. Do not make excuses for the candidate or rationalize concerning behaviors1307. Be direct and clear in your final recommendation1318. Report exact quotes from the transcript - do not correct or modify what the candidate actually said1329. Consider the full context of statements before labeling them as green or red flags13310. When a candidate provides multiple concrete examples with metrics for a skill area (e.g., impact measurement), this must be recognized as a strength13411. Distinguish between minor pronunciation/naming issues (which may be due to language barriers) and significant misunderstandings of core products or services (e.g., describing hx Renew as a model rather than a SaaS platform)13512. Do not mischaracterize enthusiasm or confidence as self-centeredness13613. If a candidate consistently demonstrates a particular skill across multiple examples, do not list it as a development area13714. Pay special attention to how candidates describe their approach to stakeholder management, team collaboration, and measuring impact13815. Ensure absolute consistency between development areas and strengths - never praise in the recommendation what was criticized as a development area13916. Eliminate all fluff and inflated language - use plain, direct language based only on evidence14017. Communication difficulties in the transcript (e.g., asking for repetition, misunderstanding questions) must be noted as a significant development area14118. Never use generic praise without specific evidence (e.g., "impressive experience" or "excellent fit")14219. The final recommendation must explicitly address each major development area and explain why it does or does not impact the hiring decision14320. Be specific about what "strong" means - avoid vague assessments like "strong technical background" without concrete examples14421. Never claim a candidate has a "clear understanding" of something they demonstrably misunderstood in the transcript14522. If a candidate has communication issues throughout the interview, this cannot be listed as a strength14623. Do not predict future performance (e.g., "will thrive") - stick to evidence from the transcript14724. Factual errors and communication difficulties should significantly impact the hiring recommendation14825. Technical experience in general is not the same as understanding of hx's specific technology - do not conflate these149"""150 151# Define user prompt template for initial analysis152USER_PROMPT_TEMPLATE = """153## Interview Transcript Analysis Request154 155Please analyze the following interview transcript between hiring manager {interviewer_name} and a candidate.156 157### Transcript:158{transcript}159 160Provide a comprehensive analysis based on the evaluation criteria, highlighting green flags and red flags for each area.161"""162 163def anonymize_names(transcript: str) -> str:164    anonymized = re.sub(r'[A-Za-z\s]+\s*\(Interviewer\)\s*:', 'Interviewer:', transcript)165    anonymized = re.sub(r'[A-Za-z\s]+\s*\(Candidate\)\s*:', 'Candidate:', anonymized)166    return anonymized167 168class InterviewChatbot:169    def __init__(self):170        self.messages = []171        self.transcript = ""172        self.interviewer_name = ""173        self.analysis_completed = False174        175    def reset(self):176        """Reset the chatbot state"""177        self.messages = []178        self.transcript = ""179        self.analysis_completed = False180        return "", "Chat has been reset. Please enter a new interview transcript."181    182    def analyze_interview(self, transcript: str) -> str:183        anonymized_transcript = anonymize_names(transcript)184        185        if not openai.api_key:186            return "Error: OpenAI API key is not set. Please set your API key in the code."187        188        try:189            # Store the transcript for future reference190            self.transcript = anonymized_transcript191            192            # Format the user prompt with the provided information193            user_prompt = USER_PROMPT_TEMPLATE.format(194                interviewer_name="Interviewer",  # Use generic role195                transcript=anonymized_transcript196            )197            198            # Initialize the conversation history199            self.messages = [200                {"role": "system", "content": SYSTEM_PROMPT},201                {"role": "user", "content": user_prompt}202            ]203            204            # Call the OpenAI API with GPT-4o mini205            response = openai.chat.completions.create(206                model="gpt-4o-mini",207                messages=self.messages,208                temperature=0.7,  # Balanced between creativity and consistency209                max_tokens=2000   # Adjust based on expected response length210            )211            212            # Extract the analysis and add to conversation history213            analysis = response.choices[0].message.content214            self.messages.append({"role": "assistant", "content": analysis})215            self.analysis_completed = True216            217            return analysis218        219        except Exception as e:220            return f"Error: {str(e)}"221    222    def chat(self, user_message: str) -> str:223        """224        Continue the conversation with follow-up questions about the interview analysis.225        226        Args:227            user_message: The user's follow-up question or comment228            229        Returns:230            AI response to the follow-up231        """232        if not self.analysis_completed:233            return "Please analyze an interview transcript first before asking follow-up questions."234        235        if not openai.api_key:236            return "Error: OpenAI API key is not set. Please set your API key in the code."237        238        try:239            # Add the user's message to the conversation history240            self.messages.append({"role": "user", "content": user_message})241            242            # Call the OpenAI API to continue the conversation243            response = openai.chat.completions.create(244                model="gpt-4o-mini",245                messages=self.messages,246                temperature=0.7,247                max_tokens=1000248            )249            250            # Extract the response and add to conversation history251            ai_response = response.choices[0].message.content252            self.messages.append({"role": "assistant", "content": ai_response})253            254            return ai_response255        256        except Exception as e:257            return f"Error: {str(e)}"258 259# Create the Gradio interface260def create_gradio_app():261    """262    Create and launch the Gradio app for interview transcript analysis with chat functionality.263    """264    chatbot = InterviewChatbot()265    266    with gr.Blocks(title="Interview Transcript Analysis Chat") as app:267        gr.Markdown("# Interview Transcript Analysis Chat")268        gr.Markdown("Analyze interview transcripts and ask follow-up questions using GPT-4o mini.")269        gr.Markdown("*Note: All personal names in transcripts will be automatically anonymized to protect privacy.*")270        271        with gr.Tab("Analysis"):272            with gr.Row():273                with gr.Column():274                    transcript = gr.Textbox(275                        label="Interview Transcript",276                        placeholder="Paste the full interview transcript here...",277                        lines=15278                    )279                    280                    analyze_button = gr.Button("Analyze Transcript", variant="primary")281                282                with gr.Column():283                    analysis_output = gr.Markdown(284                        label="Analysis Results",285                        value="Results will appear here after analysis."286                    )287        288        with gr.Tab("Chat"):289            chat_history = gr.Chatbot(label="Conversation", type="messages")290            291            with gr.Row():292                chat_input = gr.Textbox(293                    label="Your Question",294                    placeholder="Ask a follow-up question about the analysis...",295                    lines=2296                )297                chat_button = gr.Button("Send", variant="primary")298            299            reset_button = gr.Button("Reset Chat")300        301        # Set up event handlers302        def update_chat_history(user_message, history):303            if not user_message:304                return history305            306            # Get AI response307            ai_response = chatbot.chat(user_message)308            309            # Update chat history with message format310            history = history + [311                {"role": "user", "content": user_message},312                {"role": "assistant", "content": ai_response}313            ]314            return history315        316        # Set up the button click events317        analyze_button.click(318            fn=chatbot.analyze_interview,319            inputs=transcript,320            outputs=analysis_output321        )322        323        chat_button.click(324            fn=update_chat_history,325            inputs=[chat_input, chat_history],326            outputs=chat_history327        ).then(328            fn=lambda: "",329            inputs=None,330            outputs=chat_input331        )332        333        reset_button.click(334            fn=chatbot.reset,335            inputs=None,336            outputs=[transcript, analysis_output]337        ).then(338            fn=lambda: [],339            inputs=None,340            outputs=chat_history341        )342        343    return app344 345# Launch the app when this script is run directly346if __name__ == "__main__":347    app = create_gradio_app()348    app.launch()349