""" app.py — Main Streamlit application for FitMatch AI Run with: streamlit run app.py """ import streamlit as st from dotenv import load_dotenv # Reads .env file for API keys from utils.resume_parser import extract_text_from_pdf, clean_text from utils.analyzer import analyze_resume, rewrite_resume, analyze_ats_keywords from utils.pdf_generator import generate_pdf # Load environment variables from .env file (for local development) load_dotenv() # ─── Page config (must be the first Streamlit command) ─── st.set_page_config(page_title="FitMatch AI", page_icon="🎯", layout="wide") # ─── App header ─── st.title("FitMatch AI 🎯") st.markdown("**Smart Resume Analyzer & Job Fit Scorer** — Powered by Llama 3 on Groq") st.markdown("---") # ─── Initialize session state ─── # session_state lets us keep data when the user switches tabs if "resume_text" not in st.session_state: st.session_state.resume_text = "" if "job_description" not in st.session_state: st.session_state.job_description = "" if "job_role" not in st.session_state: st.session_state.job_role = "" if "results" not in st.session_state: st.session_state.results = None # ─── Create the three tabs ─── tab1, tab2, tab3 = st.tabs(["📄 Resume", "💼 Job Target", "📊 Results"]) # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # TAB 1 — Resume Input # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ with tab1: st.header("Upload or Paste Your Resume") # Two columns: one for upload, one for paste col1, col2 = st.columns(2) with col1: st.subheader("Option A: Upload PDF") uploaded_file = st.file_uploader( "Choose a PDF file", type=["pdf"], help="Upload your resume as a PDF file", ) if uploaded_file is not None: # Extract text from the uploaded PDF extracted = extract_text_from_pdf(uploaded_file) st.session_state.resume_text = clean_text(extracted) st.success("PDF uploaded and text extracted!") with col2: st.subheader("Option B: Paste Text") pasted_text = st.text_area( "Paste your resume text here", height=300, placeholder="Copy and paste your resume content here...", value=st.session_state.resume_text, ) # Update session state if user types/pastes something if pasted_text: st.session_state.resume_text = clean_text(pasted_text) # Show what we have so far if st.session_state.resume_text: with st.expander("👀 Preview extracted resume text", expanded=False): st.text(st.session_state.resume_text[:3000]) # Show first 3000 chars st.info(f"✅ Resume loaded — {len(st.session_state.resume_text)} characters") else: st.warning("No resume loaded yet. Upload a PDF or paste text above.") # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # TAB 2 — Job Target Input # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ with tab2: st.header("What Role Are You Targeting?") st.subheader("Option A: Paste a Job Description") jd_input = st.text_area( "Paste the full job description here", height=250, placeholder="Paste the job posting text here...", value=st.session_state.job_description, ) st.session_state.job_description = jd_input st.markdown("**— OR —**") st.subheader("Option B: Just Enter a Job Title") role_input = st.text_input( "Type a job role (e.g. 'Data Analyst', 'Python Developer')", value=st.session_state.job_role, placeholder="e.g. Frontend Developer", ) st.session_state.job_role = role_input # Quick status check if jd_input.strip(): st.info("✅ Job description provided — this will be used for analysis.") elif role_input.strip(): st.info("✅ Job role provided — the AI will generate a typical JD for this role.") else: st.warning("Please provide a job description or job role above.") # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # TAB 3 — Analysis Results # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ with tab3: st.header("Your Fit Analysis") # Check if we have both inputs has_resume = bool(st.session_state.resume_text.strip()) has_job = bool(st.session_state.job_description.strip() or st.session_state.job_role.strip()) if not has_resume: st.warning("⬅️ Go to the **Resume** tab and upload or paste your resume first.") elif not has_job: st.warning("⬅️ Go to the **Job Target** tab and enter a job description or role.") else: # Show the Analyze button only when both inputs are ready if st.button("🔍 Analyze Now", type="primary", use_container_width=True): with st.spinner("Analyzing your resume with AI... This takes a few seconds."): results = analyze_resume( resume_text=st.session_state.resume_text, job_description=st.session_state.job_description, job_role=st.session_state.job_role, ) st.session_state.results = results # ─── Display results if we have them ─── if st.session_state.results: results = st.session_state.results # Check for errors if "error" in results: st.error(f"❌ {results['error']}") if "raw_response" in results: with st.expander("Show raw AI response (for debugging)"): st.code(results["raw_response"]) else: # ── Show Generated JD (if role-only mode was used) ── if "generated_jd" in results: with st.expander("📝 Generated Job Description (AI-created for this role)"): st.write(results["generated_jd"]) # ── Row 1: Fit Score ── score = results.get("fit_score", 0) # Pick color based on score if score >= 70: color = "🟢" bar_color = "#28a745" # green elif score >= 50: color = "🟡" bar_color = "#ffc107" # yellow else: color = "🔴" bar_color = "#dc3545" # red # Big score display st.markdown( f"
" "Built with Streamlit + Groq (Llama 3) | FitMatch AI Workshop Demo" "
", unsafe_allow_html=True, )