import streamlit as st from utils.parser import parse_cv, extract_education_level, identify_cv_type from utils.cv_scoring import calculate_cv_score from utils.suggestions import ( get_certification_suggestions, get_higher_education_suggestions, get_visa_recommendations, get_career_advice, get_job_listings, ) from utils.visualizer import generate_timeline from PIL import Image from fpdf import FPDF import matplotlib.pyplot as plt import tempfile import io # ------------------ PDF Generation Function ------------------ def generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig): pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=12) pdf.cell(200, 10, txt="CV Analysis Report", ln=True, align="C") pdf.ln(10) pdf.cell(200, 10, txt=f"CV Type: {cv_type}", ln=True) pdf.cell(200, 10, txt=f"Education Level: {education_level}", ln=True) pdf.cell(200, 10, txt=f"CV Score: {score}/100", ln=True) pdf.ln(5) pdf.set_font("Arial", style="B", size=12) pdf.cell(200, 10, txt="Score Breakdown:", ln=True) pdf.set_font("Arial", size=12) for k, v in score_breakdown.items(): pdf.cell(200, 10, txt=f"- {k}: {v}", ln=True) pdf.ln(5) def add_list_to_pdf(title, items): pdf.set_font("Arial", style="B", size=12) pdf.cell(200, 10, txt=title, ln=True) pdf.set_font("Arial", size=12) if isinstance(items, list): for item in items: pdf.multi_cell(0, 10, f"- {item}") else: pdf.multi_cell(0, 10, str(items)) pdf.ln(5) add_list_to_pdf("Certification Suggestions:", certs) add_list_to_pdf("Higher Education Suggestions:", edu) add_list_to_pdf("Visa Recommendations:", visa) add_list_to_pdf("Career Advice:", advice) add_list_to_pdf("Job Listings:", jobs) # Save the figure as an image and insert into PDF with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile: fig.savefig(tmpfile.name, bbox_inches='tight') pdf.add_page() pdf.image(tmpfile.name, x=10, y=20, w=pdf.w - 20) return pdf # ------------------ Streamlit App ------------------ st.title("Smart CV Analyzer & Career Roadmap") uploaded_file = st.file_uploader("Upload your CV in PDF format", type=["pdf"]) if uploaded_file is not None: with open("temp_cv.pdf", "wb") as f: f.write(uploaded_file.getbuffer()) parsed_text = parse_cv("temp_cv.pdf") education_level = extract_education_level(parsed_text) cv_type = identify_cv_type(parsed_text) score, score_breakdown = calculate_cv_score(parsed_text, education_level) st.header("CV Analysis Results") st.write(f"**CV Type:** {cv_type}") st.write(f"**Education Level:** {education_level}") st.write(f"### Overall CV Score: {score} / 100") st.write("### Score Breakdown:") for k, v in score_breakdown.items(): st.write(f"- {k}: {v}") with st.expander("Certification Suggestions"): certs = get_certification_suggestions(parsed_text) st.write(certs) with st.expander("Higher Education Suggestions"): edu = get_higher_education_suggestions(parsed_text) st.write(edu) with st.expander("Visa Recommendations"): visa = get_visa_recommendations(parsed_text) st.write(visa) with st.expander("Career Advice"): advice = get_career_advice(parsed_text) st.write(advice) with st.expander("Job Listings"): jobs = get_job_listings(parsed_text) for job in jobs: st.write(f"- {job}") st.header("📈 Career Roadmap Timeline") fig = generate_timeline(cv_type, education_level, score) st.pyplot(fig) # --- PDF Download Button --- # --- PDF Download Button --- st.subheader("Download Report") # Generate the PDF as a string pdf_bytes = generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig).output(dest='S').encode('latin1') # Display a single download button st.download_button( label="📄 Download CV Analysis Report (PDF)", data=pdf_bytes, file_name="cv_analysis_report.pdf", mime="application/pdf" )