Spaces:
Sleeping
Sleeping
Create ai_technical_doc.py
Browse files- tools/ai_technical_doc.py +69 -0
tools/ai_technical_doc.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tools/ai_technical_doc.py
|
| 2 |
+
import datetime
|
| 3 |
+
import re
|
| 4 |
+
from fpdf import FPDF
|
| 5 |
+
from langdetect import detect
|
| 6 |
+
|
| 7 |
+
# === PDF Export Function ===
|
| 8 |
+
def export_text_to_pdf(text, output_path=None, language="en"):
|
| 9 |
+
if output_path is None:
|
| 10 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 11 |
+
output_path = f"technical_documentation_{timestamp}.pdf"
|
| 12 |
+
|
| 13 |
+
pdf = FPDF()
|
| 14 |
+
pdf.add_page()
|
| 15 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
| 16 |
+
|
| 17 |
+
pdf.set_font("Arial", 'B', 16)
|
| 18 |
+
pdf.set_text_color(0, 51, 102)
|
| 19 |
+
title = "Technical Documentation - AI Act (Art. 11)" if language == "en" else "Documentation Technique - AI Act"
|
| 20 |
+
pdf.cell(0, 15, title, ln=True, align='C')
|
| 21 |
+
pdf.ln(10)
|
| 22 |
+
|
| 23 |
+
pdf.set_font("Arial", '', 12)
|
| 24 |
+
pdf.set_text_color(0, 0, 0)
|
| 25 |
+
for line in text.strip().split('\n'):
|
| 26 |
+
line = line.strip()
|
| 27 |
+
if line.startswith("## "):
|
| 28 |
+
section = line.replace("## ", "").strip()
|
| 29 |
+
pdf.set_font("Arial", 'B', 13)
|
| 30 |
+
pdf.set_text_color(30, 30, 120)
|
| 31 |
+
pdf.ln(8)
|
| 32 |
+
pdf.cell(0, 10, section, ln=True)
|
| 33 |
+
pdf.set_font("Arial", '', 12)
|
| 34 |
+
pdf.set_text_color(0, 0, 0)
|
| 35 |
+
elif line.startswith("- **"):
|
| 36 |
+
match = re.match(r"- \*\*(.+?)\*\*: (.+)", line)
|
| 37 |
+
if match:
|
| 38 |
+
label, value = match.groups()
|
| 39 |
+
pdf.set_font("Arial", 'B', 12)
|
| 40 |
+
pdf.cell(0, 10, f"{label}:", ln=True)
|
| 41 |
+
pdf.set_font("Arial", '', 12)
|
| 42 |
+
pdf.multi_cell(0, 10, value)
|
| 43 |
+
elif line == "---":
|
| 44 |
+
pdf.line(10, pdf.get_y(), 200, pdf.get_y())
|
| 45 |
+
pdf.ln(5)
|
| 46 |
+
else:
|
| 47 |
+
pdf.multi_cell(0, 10, line)
|
| 48 |
+
pdf.output(output_path)
|
| 49 |
+
return output_path
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# === Questions ===
|
| 53 |
+
QUESTIONS = [
|
| 54 |
+
("system_name", "What is the name of your AI system?"),
|
| 55 |
+
("provider", "Who is the provider or developer of the system?"),
|
| 56 |
+
("intended_purpose", "What is the intended purpose of the system?"),
|
| 57 |
+
("architecture", "Describe the system architecture."),
|
| 58 |
+
("training_data", "What kind of training data is used?"),
|
| 59 |
+
("testing_methodology", "How was the system tested and validated?"),
|
| 60 |
+
("performance_metrics", "What are the system's performance metrics?"),
|
| 61 |
+
("risk_management", "What risk management measures were taken?"),
|
| 62 |
+
("cybersecurity", "What cybersecurity measures are in place?"),
|
| 63 |
+
("human_oversight", "How is human oversight implemented?"),
|
| 64 |
+
("versioning", "How is version control maintained?"),
|
| 65 |
+
("recordkeeping", "How are logs and records maintained?")
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
def get_questions():
|
| 69 |
+
return QUESTIONS
|