Download test_pdf_generation.py from Fuzure/sheami: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/Fuzure/sheami/resolve/main/test_pdf_generation.py
- Command line
-
hf download hf://spaces/Fuzure/sheami/test_pdf_generation.py
-
curl -L -o test_pdf_generation.py https://huggingface.co/spaces/Fuzure/sheami/resolve/main/test_pdf_generation.py
1.49 kB
| import os | |
| import tempfile | |
| import matplotlib.pyplot as plt | |
| import base64 | |
| from weasyprint import HTML | |
| from config import SheamiConfig | |
| from pdf_helper import generate_pdf | |
| def test_generate_pdf(): | |
| from pathlib import Path | |
| # Temporary directory for plots | |
| tmp_dir = tempfile.mkdtemp() | |
| # 1. Fake interpretation HTML | |
| interpretation_html = """ | |
| <h1>Test Patient: John Doe</h1> | |
| <p>Age: 45, Sex: Male</p> | |
| <p>Clinical Summary:</p> | |
| <ul> | |
| <li>All vitals normal ✅</li> | |
| <li>Minor deviation in cholesterol ▲</li> | |
| <li>Vitamin D slightly low ▼</li> | |
| </ul> | |
| """ | |
| # 2. Generate 4 fake plots | |
| plot_files = [] | |
| for i in range(4): | |
| plt.figure(figsize=(4,3)) | |
| plt.plot([1,2,3,4], [i*2+1, i*2+2, i*2+1, i*2+3], marker='o') | |
| plt.title(f"Test Plot {i+1}") | |
| plt.xlabel("X") | |
| plt.ylabel("Y") | |
| plot_path = os.path.join(tmp_dir, f"plot_{i+1}.png") | |
| plt.savefig(plot_path) | |
| plt.close() | |
| plot_files.append((f"Test {i+1}", plot_path)) | |
| # 3. Use your SheamiConfig logo path, or fallback to a sample image | |
| logo_path = SheamiConfig.logo_path if hasattr(SheamiConfig, 'logo_path') else plot_files[0][1] | |
| # 4. Call the generate_pdf function | |
| pdf_path = os.path.join(tmp_dir, "test_report.pdf") | |
| generate_pdf(pdf_path=pdf_path, interpretation_html=interpretation_html, plot_files=plot_files) | |
| print(f"Test PDF generated at: {pdf_path}") | |
| test_generate_pdf() |