Dave67350 commited on
Commit
f9464bb
·
verified ·
1 Parent(s): c5f6e65

Update tools/ai_act_generator.py

Browse files
Files changed (1) hide show
  1. tools/ai_act_generator.py +43 -6
tools/ai_act_generator.py CHANGED
@@ -22,19 +22,56 @@ def export_text_to_pdf(text, output_path=None, language="fr"):
22
  if output_path is None:
23
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
24
  output_path = f"ai_act_register_{timestamp}.pdf"
 
25
  pdf = FPDF()
26
  pdf.add_page()
27
  pdf.set_auto_page_break(auto=True, margin=15)
28
- pdf.set_font("Arial", size=12)
29
 
 
 
 
30
  title = "AI Act Compliance Register" if language == "en" else "Registre de Conformité AI Act"
31
- pdf.set_font("Arial", 'B', 14)
32
- pdf.cell(0, 10, title, ln=True)
33
  pdf.ln(10)
34
- pdf.set_font("Arial", size=12)
35
 
36
- for line in text.split('\n'):
37
- pdf.multi_cell(0, 10, line)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  pdf.output(output_path)
40
  return output_path
 
22
  if output_path is None:
23
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
24
  output_path = f"ai_act_register_{timestamp}.pdf"
25
+
26
  pdf = FPDF()
27
  pdf.add_page()
28
  pdf.set_auto_page_break(auto=True, margin=15)
 
29
 
30
+ # Title
31
+ pdf.set_font("Arial", 'B', 16)
32
+ pdf.set_text_color(0, 51, 102)
33
  title = "AI Act Compliance Register" if language == "en" else "Registre de Conformité AI Act"
34
+ pdf.cell(0, 15, title, ln=True, align='C')
 
35
  pdf.ln(10)
 
36
 
37
+ # Subtitle
38
+ pdf.set_font("Arial", 'I', 12)
39
+ pdf.set_text_color(90, 90, 90)
40
+ subtitle = f"Generated on {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
41
+ pdf.cell(0, 10, subtitle, ln=True, align='C')
42
+ pdf.ln(5)
43
+
44
+ # Reset style for body
45
+ pdf.set_font("Arial", '', 12)
46
+ pdf.set_text_color(0, 0, 0)
47
+
48
+ # Parse and format sections
49
+ for line in text.strip().split('\n'):
50
+ line = line.strip()
51
+ if line.startswith("## "):
52
+ section_title = line.replace("## ", "").strip()
53
+ pdf.set_font("Arial", 'B', 13)
54
+ pdf.set_text_color(30, 30, 120)
55
+ pdf.ln(8)
56
+ pdf.cell(0, 10, section_title, ln=True)
57
+ pdf.ln(2)
58
+ pdf.set_font("Arial", '', 12)
59
+ pdf.set_text_color(0, 0, 0)
60
+ elif line.startswith("- **"):
61
+ key_value = re.match(r"- \*\*(.+?)\*\*: (.+)", line)
62
+ if key_value:
63
+ label, answer = key_value.groups()
64
+ pdf.set_font("Arial", 'B', 12)
65
+ pdf.cell(0, 10, f"{label}:", ln=True)
66
+ pdf.set_font("Arial", '', 12)
67
+ pdf.multi_cell(0, 10, f"{answer}")
68
+ pdf.ln(2)
69
+ elif line.strip() == "---":
70
+ pdf.line(10, pdf.get_y(), 200, pdf.get_y())
71
+ pdf.ln(5)
72
+ else:
73
+ pdf.multi_cell(0, 10, line)
74
+ pdf.ln(2)
75
 
76
  pdf.output(output_path)
77
  return output_path