Spaces:
Sleeping
Sleeping
Upload export/pdf_export.py with huggingface_hub
Browse files- export/pdf_export.py +29 -0
export/pdf_export.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Lightweight PDF export helpers.
|
| 2 |
+
|
| 3 |
+
This module provides a minimal 'export to PDF' helper. To avoid adding a
|
| 4 |
+
heavy dependency (like reportlab) in this exercise the function will write
|
| 5 |
+
a simple plaintext representation to a .pdf file. For production use
|
| 6 |
+
replace this with a real PDF renderer.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from typing import Any, Dict, List
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def save_results_pdf(path: str, results: List[Dict[str, Any]]) -> None:
|
| 13 |
+
"""Write a plaintext representation of results to the given path.
|
| 14 |
+
|
| 15 |
+
Note: This is a lightweight stub. The resulting file will be valid but
|
| 16 |
+
not a true typeset PDF. Replace with a proper PDF generation flow if
|
| 17 |
+
needed.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
path: Output file path (recommended .pdf extension).
|
| 21 |
+
results: List of result dictionaries to include.
|
| 22 |
+
"""
|
| 23 |
+
with open(path, "w", encoding="utf-8") as f:
|
| 24 |
+
for r in results:
|
| 25 |
+
f.write(f"Text: {r.get('text', '')}\n")
|
| 26 |
+
f.write(
|
| 27 |
+
f"Bias: {r.get('bias_probability', '')} ({r.get('bias_class', '')})\n"
|
| 28 |
+
)
|
| 29 |
+
f.write("---\n")
|