Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| from openai import OpenAI | |
| # Initialize OpenRouter client | |
| client = OpenAI( | |
| base_url="https://openrouter.ai/api/v1", | |
| api_key=os.environ.get("OPENROUTER_API_KEY"), | |
| ) | |
| def analyze_skills_gap(resume_text, job_description): | |
| """Analyze the gap between resume and job requirements.""" | |
| if not resume_text.strip() or not job_description.strip(): | |
| return "Please provide both resume and job description.", "", "" | |
| # Main analysis prompt | |
| analysis_prompt = f"""You are a career advisor analyzing a resume against a job description. | |
| **Resume:** | |
| {resume_text} | |
| **Job Description:** | |
| {job_description} | |
| Provide a detailed analysis in the following format: | |
| ## β Matching Skills | |
| List skills/experiences the candidate has that match the job requirements. | |
| ## β Missing Skills | |
| List skills/requirements from the job that are NOT found in the resume. | |
| ## β οΈ Skills to Strengthen | |
| List skills mentioned in the resume but need more emphasis or development. | |
| ## π‘ Recommendations | |
| Provide 3-5 specific, actionable recommendations to bridge the gap. | |
| ## π Match Score | |
| Give an overall match percentage (0-100%) with brief justification. | |
| Be specific and constructive.""" | |
| # Learning resources prompt | |
| learning_prompt = f"""Based on this skills gap analysis, suggest specific learning resources. | |
| **Missing Skills from Analysis:** | |
| {job_description} | |
| For each major missing skill, provide: | |
| 1. Skill name | |
| 2. Why it's important for this role | |
| 3. 2-3 specific learning resources (courses, certifications, books, or platforms) | |
| 4. Estimated time to learn basics | |
| Format as a clear, organized list.""" | |
| try: | |
| # Get main analysis | |
| analysis_response = client.chat.completions.create( | |
| model="google/gemma-2-9b-it:free", | |
| messages=[{"role": "user", "content": analysis_prompt}], | |
| max_tokens=1500, | |
| temperature=0.7, | |
| ) | |
| main_analysis = analysis_response.choices[0].message.content | |
| # Get learning recommendations | |
| learning_response = client.chat.completions.create( | |
| model="google/gemma-2-9b-it:free", | |
| messages=[{"role": "user", "content": learning_prompt}], | |
| max_tokens=1000, | |
| temperature=0.7, | |
| ) | |
| learning_resources = learning_response.choices[0].message.content | |
| # Generate quick action items | |
| action_prompt = f"""Based on this analysis: | |
| {main_analysis} | |
| Create 5 immediate action items the candidate should take this week to improve their application. Be specific and actionable. Format as a numbered list.""" | |
| action_response = client.chat.completions.create( | |
| model="google/gemma-2-9b-it:free", | |
| messages=[{"role": "user", "content": action_prompt}], | |
| max_tokens=400, | |
| temperature=0.7, | |
| ) | |
| action_items = action_response.choices[0].message.content | |
| return main_analysis, learning_resources, action_items | |
| except Exception as e: | |
| error_msg = f"Error: {str(e)}\n\nMake sure your OPENROUTER_API_KEY is set correctly." | |
| return error_msg, "", "" | |
| # Create Gradio interface | |
| with gr.Blocks(title="Resume Skills Gap Analyzer", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown(""" | |
| # π― Resume Skills Gap Analyzer | |
| Find out exactly what skills you need to land your dream job. This tool: | |
| - Compares your resume to any job description | |
| - Identifies missing skills and strengths | |
| - Provides learning resources and action plans | |
| - Gives you a match score | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| resume_input = gr.Textbox( | |
| label="π Your Resume", | |
| placeholder="Paste your resume text here...", | |
| lines=12 | |
| ) | |
| job_input = gr.Textbox( | |
| label="πΌ Target Job Description", | |
| placeholder="Paste the job description here...", | |
| lines=12 | |
| ) | |
| analyze_btn = gr.Button("π Analyze Skills Gap", variant="primary", size="lg") | |
| with gr.Column(): | |
| analysis_output = gr.Textbox( | |
| label="π Gap Analysis", | |
| lines=15, | |
| show_copy_button=True | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| learning_output = gr.Textbox( | |
| label="π Learning Resources", | |
| lines=10, | |
| show_copy_button=True | |
| ) | |
| with gr.Column(): | |
| action_output = gr.Textbox( | |
| label="β Action Items (This Week)", | |
| lines=10, | |
| show_copy_button=True | |
| ) | |
| # Example inputs | |
| gr.Markdown("### π Try This Example:") | |
| gr.Examples( | |
| examples=[ | |
| [ | |
| """John Smith | |
| Data Analyst | 3 years experience | |
| SKILLS: | |
| - Python (Pandas, NumPy) | |
| - SQL (MySQL, PostgreSQL) | |
| - Excel (VLOOKUP, Pivot Tables) | |
| - Tableau | |
| - Statistical analysis | |
| EXPERIENCE: | |
| Data Analyst at TechCorp (2021-2024) | |
| - Analyzed customer behavior data | |
| - Created dashboards in Tableau | |
| - Wrote SQL queries for reporting | |
| - Collaborated with marketing team | |
| Junior Analyst at StartupXYZ (2020-2021) | |
| - Data cleaning and preprocessing | |
| - Basic statistical analysis | |
| - Excel reporting | |
| EDUCATION: | |
| BS in Mathematics, State University (2020)""", | |
| """Senior Data Analyst | |
| We're looking for an experienced Data Analyst to join our team. | |
| Requirements: | |
| - 4+ years of data analysis experience | |
| - Advanced Python (pandas, scikit-learn, matplotlib) | |
| - SQL expertise (complex queries, optimization) | |
| - Experience with A/B testing and experimental design | |
| - Machine learning fundamentals | |
| - Cloud platforms (AWS or GCP) | |
| - Data visualization (Tableau or Power BI) | |
| - Strong communication skills | |
| Nice to have: | |
| - R programming | |
| - Spark/big data tools | |
| - ETL pipeline experience | |
| - Experience with dbt | |
| You'll be: | |
| - Leading analysis projects | |
| - Building predictive models | |
| - Collaborating with data engineers | |
| - Presenting insights to stakeholders""" | |
| ] | |
| ], | |
| inputs=[resume_input, job_input], | |
| label=None | |
| ) | |
| # Connect the button | |
| analyze_btn.click( | |
| fn=analyze_skills_gap, | |
| inputs=[resume_input, job_input], | |
| outputs=[analysis_output, learning_output, action_output] | |
| ) | |
| gr.Markdown(""" | |
| --- | |
| ### π‘ Tips for Best Results: | |
| - Include your full resume with skills, experience, and education | |
| - Paste the complete job description | |
| - The more detail you provide, the better the analysis | |
| - Use this to tailor your resume for specific applications | |
| """) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() |