simikkk commited on
Commit
a665d76
·
verified ·
1 Parent(s): 2187522

Update report_generator.py

Browse files
Files changed (1) hide show
  1. 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.lib.styles import getSampleStyleSheet, ParagraphStyle
4
- from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
5
- from reportlab.lib.units import cm
6
- import tempfile
7
 
8
- def score_color(score: int):
9
- if score >= 75:
10
- return colors.HexColor("#16a34a")
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
- story = []
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
- # Top 3 akce
67
- story.append(Paragraph("Your 3 Most Important Actions", h2))
68
- for i, action in enumerate(analysis.get("top_3_actions", []), 1):
69
- story.append(Paragraph(f"{i}. {action}", body))
70
- story.append(Spacer(1, 0.3*cm))
71
 
72
- # Chybějící keywords
73
- story.append(Paragraph("Missing Keywords", h2))
74
- kw_data = [["Keyword", "Why it matters"]]
 
75
  for kw in analysis.get("missing_keywords", []):
76
- kw_data.append([kw.get("keyword", ""), kw.get("why_it_matters", "")])
77
- if len(kw_data) > 1:
78
- kw_table = Table(kw_data, colWidths=[5*cm, 12*cm])
79
- kw_table.setStyle(TableStyle([
80
- ("BACKGROUND", (0, 0), (-1, 0), colors.HexColor("#1e293b")),
81
- ("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
82
- ("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
83
- ("GRID", (0, 0), (-1, -1), 0.5, colors.HexColor("#e2e8f0")),
84
- ("PADDING", (0, 0), (-1, -1), 6),
85
- ("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.white, colors.HexColor("#f8fafc")]),
86
- ("FONTSIZE", (0, 0), (-1, -1), 9),
87
- ]))
88
- story.append(kw_table)
89
- story.append(Spacer(1, 0.3*cm))
90
-
91
- # Slabé sekce
92
- story.append(Paragraph("Sections to Strengthen (rewrite in your own words)", h2))
93
- for sec in analysis.get("weak_sections", []):
94
- story.append(Paragraph(f"<b>Original:</b> \"{sec.get('original_phrase', '')}\"", body))
95
- story.append(Paragraph(f"<b>Problem:</b> {sec.get('problem', '')}", body))
96
- story.append(Paragraph(f"<b>What to convey:</b> {sec.get('what_to_convey_instead', '')}", body))
97
- story.append(Paragraph(f"<b>Direction:</b> {sec.get('example_direction', '')}", body))
98
- story.append(Spacer(1, 0.2*cm))
99
-
100
- # ATS varování
101
- story.append(Paragraph("ATS Warnings", h2))
102
- for w in analysis.get("ats_warnings", []):
103
- story.append(Paragraph(f"⚠ {w}", body))
104
- story.append(Spacer(1, 0.3*cm))
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