File size: 4,297 Bytes
cdf0ebd
 
 
 
 
 
 
 
75f545b
cdf0ebd
8102e23
c706984
 
a2e5023
c706984
cdf0ebd
 
a2e5023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6a011e
cdf0ebd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcc6fe9
 
41210ec
dcc6fe9
 
 
41210ec
dcc6fe9
 
 
41210ec
dcc6fe9
 
 
41210ec
dcc6fe9
 
 
41210ec
dcc6fe9
 
 
 
41210ec
8102e23
53bf7e9
8102e23
6100e2f
914b2bd
a2e5023
 
f51020c
914b2bd
 
f51020c
914b2bd
f51020c
 
914b2bd
f51020c
 
 
 
914b2bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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"
    )