Spaces:
Sleeping
Sleeping
Update report_generator.py
Browse files- report_generator.py +44 -119
report_generator.py
CHANGED
|
@@ -1,126 +1,51 @@
|
|
| 1 |
from reportlab.lib.pagesizes import A4
|
|
|
|
| 2 |
from reportlab.lib import colors
|
| 3 |
-
from reportlab.
|
| 4 |
-
from reportlab.
|
| 5 |
-
from reportlab.lib.units import cm
|
| 6 |
-
import tempfile
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
elif score >= 50:
|
| 12 |
-
return colors.HexColor("#d97706")
|
| 13 |
-
else:
|
| 14 |
-
return colors.HexColor("#dc2626")
|
| 15 |
-
|
| 16 |
-
def generate_pdf_report(analysis: dict, is_pro: bool = False) -> str:
|
| 17 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
| 18 |
-
doc = SimpleDocTemplate(
|
| 19 |
-
tmp.name, pagesize=A4,
|
| 20 |
-
leftMargin=2*cm, rightMargin=2*cm,
|
| 21 |
-
topMargin=2*cm, bottomMargin=2*cm
|
| 22 |
-
)
|
| 23 |
styles = getSampleStyleSheet()
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
title_style = ParagraphStyle("title", fontSize=22, spaceAfter=6,
|
| 27 |
-
textColor=colors.HexColor("#1e293b"), fontName="Helvetica-Bold")
|
| 28 |
-
sub_style = ParagraphStyle("sub", fontSize=11, spaceAfter=20,
|
| 29 |
-
textColor=colors.HexColor("#64748b"))
|
| 30 |
-
h2 = ParagraphStyle("h2", fontSize=13, spaceAfter=6, spaceBefore=14,
|
| 31 |
-
fontName="Helvetica-Bold", textColor=colors.HexColor("#1e293b"))
|
| 32 |
-
body = ParagraphStyle("body", fontSize=10, spaceAfter=4,
|
| 33 |
-
textColor=colors.HexColor("#334155"), leading=14)
|
| 34 |
-
wm_style = ParagraphStyle("wm", fontSize=9, textColor=colors.HexColor("#94a3b8"),
|
| 35 |
-
spaceAfter=0, spaceBefore=20)
|
| 36 |
-
|
| 37 |
-
story.append(Paragraph("ResumeLens AI Report", title_style))
|
| 38 |
-
story.append(Paragraph("Personalized CV Analysis — improve in your own words", sub_style))
|
| 39 |
-
|
| 40 |
-
if "error" in analysis:
|
| 41 |
-
story.append(Paragraph(f"Error: {analysis['error']}", styles["Normal"]))
|
| 42 |
-
doc.build(story)
|
| 43 |
-
return tmp.name
|
| 44 |
-
|
| 45 |
-
score = analysis.get("match_score", 0)
|
| 46 |
-
col = score_color(score)
|
| 47 |
-
|
| 48 |
-
# Score tabulka
|
| 49 |
-
score_data = [
|
| 50 |
-
["Match Score", f"{score}/100"],
|
| 51 |
-
["Summary", analysis.get("score_explanation", "")],
|
| 52 |
-
]
|
| 53 |
-
score_table = Table(score_data, colWidths=[4*cm, 13*cm])
|
| 54 |
-
score_table.setStyle(TableStyle([
|
| 55 |
-
("BACKGROUND", (0, 0), (0, -1), colors.HexColor("#f1f5f9")),
|
| 56 |
-
("TEXTCOLOR", (1, 0), (1, 0), col),
|
| 57 |
-
("FONTSIZE", (1, 0), (1, 0), 20),
|
| 58 |
-
("FONTNAME", (1, 0), (1, 0), "Helvetica-Bold"),
|
| 59 |
-
("GRID", (0, 0), (-1, -1), 0.5, colors.HexColor("#e2e8f0")),
|
| 60 |
-
("PADDING", (0, 0), (-1, -1), 8),
|
| 61 |
-
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
| 62 |
-
]))
|
| 63 |
-
story.append(score_table)
|
| 64 |
-
story.append(Spacer(1, 0.5*cm))
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
story.append(Paragraph(f"{i}. {action}", body))
|
| 70 |
-
story.append(Spacer(1, 0.3*cm))
|
| 71 |
|
| 72 |
-
# Chybějící
|
| 73 |
-
|
| 74 |
-
kw_data = [["
|
|
|
|
| 75 |
for kw in analysis.get("missing_keywords", []):
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
(
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
#
|
| 92 |
-
|
| 93 |
-
for
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
# Silné stránky
|
| 107 |
-
story.append(Paragraph("Your Strengths", h2))
|
| 108 |
-
for s in analysis.get("strengths", []):
|
| 109 |
-
story.append(Paragraph(f"✓ {s}", body))
|
| 110 |
-
story.append(Spacer(1, 0.3*cm))
|
| 111 |
-
|
| 112 |
-
# LinkedIn nápady
|
| 113 |
-
story.append(Paragraph("LinkedIn Headline Ideas", h2))
|
| 114 |
-
for h in analysis.get("linkedin_headline_ideas", []):
|
| 115 |
-
story.append(Paragraph(f"→ {h}", body))
|
| 116 |
-
|
| 117 |
-
# Watermark pro free
|
| 118 |
-
if not is_pro:
|
| 119 |
-
story.append(Spacer(1, 1*cm))
|
| 120 |
-
story.append(Paragraph(
|
| 121 |
-
"Generated with ResumeLens AI (Free Plan) · Upgrade at resumelens.hf.space for full history & clean export",
|
| 122 |
-
wm_style
|
| 123 |
-
))
|
| 124 |
-
|
| 125 |
-
doc.build(story)
|
| 126 |
-
return tmp.name
|
|
|
|
| 1 |
from reportlab.lib.pagesizes import A4
|
| 2 |
+
from reportlab.pdfgen import canvas
|
| 3 |
from reportlab.lib import colors
|
| 4 |
+
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
|
| 5 |
+
from reportlab.lib.styles import getSampleStyleSheet
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def generate_pdf_report(analysis, is_pro=False):
|
| 8 |
+
filename = "report.pdf"
|
| 9 |
+
doc = SimpleDocTemplate(filename, pagesize=A4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
styles = getSampleStyleSheet()
|
| 11 |
+
elements = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Nadpis
|
| 14 |
+
elements.append(Paragraph(f"Resume Analysis Score: {analysis.get('match_score', 0)}/100", styles['Title']))
|
| 15 |
+
elements.append(Spacer(1, 12))
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Chybějící klíčová slova (OPRAVENÁ ČÁST)
|
| 18 |
+
elements.append(Paragraph("Chybějící klíčová slova:", styles['Heading2']))
|
| 19 |
+
kw_data = [["Klíčové slovo", "Proč je důležité"]]
|
| 20 |
+
|
| 21 |
for kw in analysis.get("missing_keywords", []):
|
| 22 |
+
# Ošetření: pokud je to dict, vezmi hodnoty, pokud string, dej ho do prvního sloupce
|
| 23 |
+
if isinstance(kw, dict):
|
| 24 |
+
kw_data.append([kw.get("keyword", ""), kw.get("why_it_matters", "")])
|
| 25 |
+
else:
|
| 26 |
+
kw_data.append([str(kw), ""])
|
| 27 |
+
|
| 28 |
+
table = Table(kw_data, colWidths=[150, 300])
|
| 29 |
+
table.setStyle(TableStyle([
|
| 30 |
+
('BACKGROUND', (0, 0), (-1, 0), colors.grey),
|
| 31 |
+
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
|
| 32 |
+
('GRID', (0, 0), (-1, -1), 1, colors.black),
|
| 33 |
+
]))
|
| 34 |
+
elements.append(table)
|
| 35 |
+
elements.append(Spacer(1, 12))
|
| 36 |
+
|
| 37 |
+
# Ostatní sekce
|
| 38 |
+
elements.append(Paragraph("Tvoje 3 nejdůležitější akce:", styles['Heading2']))
|
| 39 |
+
for action in analysis.get("top_3_actions", []):
|
| 40 |
+
text = action if isinstance(action, str) else str(action)
|
| 41 |
+
elements.append(Paragraph(f"- {text}", styles['Normal']))
|
| 42 |
+
|
| 43 |
+
elements.append(Spacer(1, 12))
|
| 44 |
+
elements.append(Paragraph("ATS Varování:", styles['Heading2']))
|
| 45 |
+
for warn in analysis.get("ats_warnings", []):
|
| 46 |
+
text = warn if isinstance(warn, str) else str(warn)
|
| 47 |
+
elements.append(Paragraph(f"- {text}", styles['Normal']))
|
| 48 |
+
|
| 49 |
+
# Vytvoření PDF
|
| 50 |
+
doc.build(elements)
|
| 51 |
+
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|