Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| import requests | |
| import spacy | |
| from PyPDF2 import PdfReader | |
| from io import BytesIO | |
| import json | |
| import os | |
| import pandas as pd | |
| # Load spaCy model | |
| nlp = spacy.load("en_core_web_sm") | |
| # App Title | |
| st.set_page_config(page_title="AI-Powered Resume Analyzer & Job Adviser", layout="wide") | |
| st.title("๐ผ AI-Powered Resume Analyzer & Job Adviser") | |
| # Tabs for Candidate and HR | |
| tab1, tab2 = st.tabs(["Candidate", "HR Recruiter"]) | |
| # Set your GROQ API details | |
| groq_api_url = "https://api.groq.com/openai/v1/chat/completions" | |
| groq_api_key = os.getenv("wbm2") # Add this in Hugging Face secrets | |
| # Function to call GROQ LLM | |
| def get_ai_response(prompt): | |
| headers = { | |
| "Authorization": f"Bearer {groq_api_key}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": "llama3-70b-8192", | |
| "messages": [ | |
| {"role": "system", "content": "You are an AI-powered job advisor and resume analyzer."}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| } | |
| response = requests.post(groq_api_url, headers=headers, json=payload) | |
| try: | |
| response.raise_for_status() | |
| data = response.json() | |
| if 'choices' in data: | |
| return data['choices'][0]['message']['content'] | |
| else: | |
| st.error("Unexpected response format from Groq API.") | |
| st.json(data) | |
| return "Error: Invalid API response format." | |
| except requests.exceptions.RequestException as e: | |
| st.error(f"Request failed: {e}") | |
| return "Error: Unable to fetch response from the AI model." | |
| # Extract text from PDF resume | |
| def extract_resume_text(uploaded_file): | |
| reader = PdfReader(uploaded_file) | |
| resume_text = "" | |
| for page in reader.pages: | |
| resume_text += page.extract_text() | |
| return resume_text | |
| # Country and Experience Inputs | |
| country_list = sorted([ | |
| "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", | |
| "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", | |
| "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", | |
| "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", | |
| "Chile", "China", "Colombia", "Comoros", "Congo (Congo-Brazzaville)", "Costa Rica", "Croatia", "Cuba", "Cyprus", | |
| "Czech Republic", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", | |
| "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", | |
| "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", | |
| "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", | |
| "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", | |
| "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", | |
| "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", | |
| "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", | |
| "Montenegro", "Morocco", "Mozambique", "Myanmar (Burma)", "Namibia", "Nauru", "Nepal", "Netherlands", | |
| "New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", "North Macedonia", "Norway", "Oman", | |
| "Pakistan", "Palau", "Palestine State", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", | |
| "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", | |
| "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", | |
| "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", | |
| "Somalia", "South Africa", "South Korea", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", | |
| "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", | |
| "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", | |
| "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", | |
| "Vatican City", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe", "Remote", "Other" | |
| ]) | |
| country = st.sidebar.selectbox("Select Country", country_list) | |
| years_experience = st.sidebar.slider("Years of Experience", 0, 40, 5) | |
| skills_input = st.sidebar.text_input("Enter Skills (comma separated)") | |
| skills = [skill.strip() for skill in skills_input.split(",") if skill.strip()] | |
| # Candidate Tab | |
| with tab1: | |
| st.header("๐ค Candidate Mode") | |
| uploaded_file = st.file_uploader("Upload your Resume (PDF only)", type="pdf") | |
| if uploaded_file: | |
| resume_text = extract_resume_text(uploaded_file) | |
| resume_doc = nlp(resume_text) | |
| st.subheader("Extracted Resume Preview") | |
| st.text_area("Resume Content", resume_text, height=300) | |
| if st.button("Analyze Resume & Get Job Advice"): | |
| prompt = f"Analyze the following resume for a candidate in {country} with {years_experience} years of experience and skills: {skills}. Provide detailed analysis, skill profiling, role suggestions, and tailored job advice.\n\nResume:\n{resume_text}" | |
| with st.spinner("Analyzing Resume and Fetching Job Market Info..."): | |
| analysis = get_ai_response(prompt) | |
| st.markdown("### ๐ฌ AI Analysis & Recommendations") | |
| st.write(analysis) | |
| # HR Recruiter Tab | |
| with tab2: | |
| st.header("๐ฅ HR Recruiter Mode") | |
| uploaded_file = st.file_uploader("Upload Candidate Resume (PDF only)", type="pdf", key="hr") | |
| if uploaded_file: | |
| resume_text = extract_resume_text(uploaded_file) | |
| st.subheader("Extracted Resume Preview") | |
| st.text_area("Resume Content", resume_text, height=300, key="hrtext") | |
| if st.button("Score Candidate & Suggest Roles"): | |
| prompt = f"You are a recruiter assistant. Evaluate this resume from the perspective of an HR professional hiring in {country}. The role requires skills: {skills} and {years_experience} years experience. Provide candidate scoring, skill match analysis, and suggest best-fit roles with insights.\n\nResume:\n{resume_text}" | |
| with st.spinner("Scoring Candidate and Fetching Suggestions..."): | |
| analysis = get_ai_response(prompt) | |
| st.markdown("### ๐ Candidate Evaluation & Suggestions") | |
| st.write(analysis) | |
| st.markdown("---") | |
| st.caption("ยฉ 2025 AI Resume Analyzer & Job Adviser | Powered by Groq + Streamlit + spaCy") | |
| st.caption("Program Developed By waqasbm | AI & ML Practitioner") |