Danial7 commited on
Commit
a2e5023
·
verified ·
1 Parent(s): 504c0b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -88
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- from utils.visualizer import generate_timeline
3
  from utils.parser import parse_cv, extract_education_level, identify_cv_type
4
  from utils.cv_scoring import calculate_cv_score
5
  from utils.suggestions import (
@@ -11,16 +10,58 @@ from utils.suggestions import (
11
  )
12
  from utils.visualizer import generate_timeline
13
  from PIL import Image
14
- import matplotlib.pyplot as plt
15
  from fpdf import FPDF
 
16
  import tempfile
17
- import base64
18
  import io
19
- import datetime
20
- from fpdf import FPDF
21
- from matplotlib.backends.backend_agg import RendererAgg
22
- import matplotlib.pyplot as plt
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  st.title("Universal Smart CV Analyzer & Career Roadmap")
25
 
26
  uploaded_file = st.file_uploader("Upload your CV in PDF format", type=["pdf"])
@@ -67,84 +108,16 @@ if uploaded_file is not None:
67
  fig = generate_timeline(cv_type, education_level, score)
68
  st.pyplot(fig)
69
 
70
- st.subheader("Download Report")
71
- if st.button("Generate PDF Report"):
72
- pdf = generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig)
73
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
74
- pdf.output(tmp_pdf.name)
75
- with open(tmp_pdf.name, "rb") as f:
76
- st.download_button(
77
- label="📄 Download CV Analysis Report (PDF)",
78
- data=f,
79
- file_name="cv_analysis_report.pdf",
80
- mime="application/pdf"
81
- )
82
-
83
-
84
-
85
-
86
- # --- Add Roadmap Chart Image ---
87
- pdf.add_page()
88
- pdf.set_font("Arial", "B", 14)
89
- pdf.cell(0, 10, "Career Roadmap Timeline", ln=True)
90
-
91
- img_buf = io.BytesIO()
92
- fig.savefig(img_buf, format="PNG", bbox_inches="tight")
93
- img_buf.seek(0)
94
-
95
- # Convert to PIL Image to get correct dimensions for PDF scaling
96
- image = Image.open(img_buf)
97
- width, height = image.size
98
- aspect = height / width
99
- pdf_width = 180 # Max width for PDF
100
- pdf.image(img_buf, x=15, y=None, w=pdf_width, h=pdf_width * aspect)
101
-
102
- pdf_buffer = io.BytesIO()
103
- pdf.output(pdf_buffer)
104
- pdf_buffer.seek(0)
105
- return pdf_buffer
106
-
107
- def generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig):
108
- pdf = FPDF()
109
- pdf.add_page()
110
- pdf.set_font("Arial", size=12)
111
-
112
- pdf.cell(200, 10, txt="CV Analysis Report", ln=True, align="C")
113
- pdf.ln(10)
114
-
115
- pdf.cell(200, 10, txt=f"CV Type: {cv_type}", ln=True)
116
- pdf.cell(200, 10, txt=f"Education Level: {education_level}", ln=True)
117
- pdf.cell(200, 10, txt=f"CV Score: {score}/100", ln=True)
118
- pdf.ln(5)
119
-
120
- pdf.set_font("Arial", style="B", size=12)
121
- pdf.cell(200, 10, txt="Score Breakdown:", ln=True)
122
- pdf.set_font("Arial", size=12)
123
- for k, v in score_breakdown.items():
124
- pdf.cell(200, 10, txt=f"- {k}: {v}", ln=True)
125
- pdf.ln(5)
126
-
127
- def add_list_to_pdf(title, items):
128
- pdf.set_font("Arial", style="B", size=12)
129
- pdf.cell(200, 10, txt=title, ln=True)
130
- pdf.set_font("Arial", size=12)
131
- if isinstance(items, list):
132
- for item in items:
133
- pdf.multi_cell(0, 10, f"- {item}")
134
- else:
135
- pdf.multi_cell(0, 10, str(items))
136
- pdf.ln(5)
137
-
138
- add_list_to_pdf("Certification Suggestions:", certs)
139
- add_list_to_pdf("Higher Education Suggestions:", edu)
140
- add_list_to_pdf("Visa Recommendations:", visa)
141
- add_list_to_pdf("Career Advice:", advice)
142
- add_list_to_pdf("Job Listings:", jobs)
143
-
144
- # Save the figure as an image and insert into PDF
145
- with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile:
146
- fig.savefig(tmpfile.name, bbox_inches='tight')
147
- pdf.add_page()
148
- pdf.image(tmpfile.name, x=10, y=20, w=pdf.w - 20)
149
-
150
- return pdf
 
1
  import streamlit as st
 
2
  from utils.parser import parse_cv, extract_education_level, identify_cv_type
3
  from utils.cv_scoring import calculate_cv_score
4
  from utils.suggestions import (
 
10
  )
11
  from utils.visualizer import generate_timeline
12
  from PIL import Image
 
13
  from fpdf import FPDF
14
+ import matplotlib.pyplot as plt
15
  import tempfile
 
16
  import io
 
 
 
 
17
 
18
+ # ------------------ PDF Generation Function ------------------
19
+ def generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig):
20
+ pdf = FPDF()
21
+ pdf.add_page()
22
+ pdf.set_font("Arial", size=12)
23
+
24
+ pdf.cell(200, 10, txt="CV Analysis Report", ln=True, align="C")
25
+ pdf.ln(10)
26
+
27
+ pdf.cell(200, 10, txt=f"CV Type: {cv_type}", ln=True)
28
+ pdf.cell(200, 10, txt=f"Education Level: {education_level}", ln=True)
29
+ pdf.cell(200, 10, txt=f"CV Score: {score}/100", ln=True)
30
+ pdf.ln(5)
31
+
32
+ pdf.set_font("Arial", style="B", size=12)
33
+ pdf.cell(200, 10, txt="Score Breakdown:", ln=True)
34
+ pdf.set_font("Arial", size=12)
35
+ for k, v in score_breakdown.items():
36
+ pdf.cell(200, 10, txt=f"- {k}: {v}", ln=True)
37
+ pdf.ln(5)
38
+
39
+ def add_list_to_pdf(title, items):
40
+ pdf.set_font("Arial", style="B", size=12)
41
+ pdf.cell(200, 10, txt=title, ln=True)
42
+ pdf.set_font("Arial", size=12)
43
+ if isinstance(items, list):
44
+ for item in items:
45
+ pdf.multi_cell(0, 10, f"- {item}")
46
+ else:
47
+ pdf.multi_cell(0, 10, str(items))
48
+ pdf.ln(5)
49
+
50
+ add_list_to_pdf("Certification Suggestions:", certs)
51
+ add_list_to_pdf("Higher Education Suggestions:", edu)
52
+ add_list_to_pdf("Visa Recommendations:", visa)
53
+ add_list_to_pdf("Career Advice:", advice)
54
+ add_list_to_pdf("Job Listings:", jobs)
55
+
56
+ # Save the figure as an image and insert into PDF
57
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmpfile:
58
+ fig.savefig(tmpfile.name, bbox_inches='tight')
59
+ pdf.add_page()
60
+ pdf.image(tmpfile.name, x=10, y=20, w=pdf.w - 20)
61
+
62
+ return pdf
63
+
64
+ # ------------------ Streamlit App ------------------
65
  st.title("Universal Smart CV Analyzer & Career Roadmap")
66
 
67
  uploaded_file = st.file_uploader("Upload your CV in PDF format", type=["pdf"])
 
108
  fig = generate_timeline(cv_type, education_level, score)
109
  st.pyplot(fig)
110
 
111
+ # --- PDF Download Button ---
112
+ st.subheader("Download Report")
113
+ if st.button("Generate PDF Report"):
114
+ pdf = generate_pdf_report(cv_type, education_level, score, score_breakdown, certs, edu, visa, advice, jobs, fig)
115
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
116
+ pdf.output(tmp_pdf.name)
117
+ with open(tmp_pdf.name, "rb") as f:
118
+ st.download_button(
119
+ label="📄 Download CV Analysis Report (PDF)",
120
+ data=f,
121
+ file_name="cv_analysis_report.pdf",
122
+ mime="application/pdf"
123
+ )