Spaces:
Running
Running
Delete src/aibom-generator/aibom_score_report.py
Browse files
src/aibom-generator/aibom_score_report.py
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
from typing import Dict
|
3 |
-
|
4 |
-
def humanize(text: str) -> str:
|
5 |
-
return text.replace('_', ' ').title()
|
6 |
-
|
7 |
-
def render_score_html(score_report: Dict[str, any]) -> str:
|
8 |
-
max_scores = score_report.get("max_scores", {
|
9 |
-
"required_fields": 20,
|
10 |
-
"metadata": 20,
|
11 |
-
"component_basic": 20,
|
12 |
-
"component_model_card": 30,
|
13 |
-
"external_references": 10
|
14 |
-
})
|
15 |
-
|
16 |
-
total_max = 100
|
17 |
-
|
18 |
-
html = f"""
|
19 |
-
<html>
|
20 |
-
<head>
|
21 |
-
<title>AIBOM Score Report</title>
|
22 |
-
<style>
|
23 |
-
body {{ font-family: Arial, sans-serif; margin: 20px; }}
|
24 |
-
h2 {{ color: #2c3e50; }}
|
25 |
-
table {{ border-collapse: collapse; width: 60%; margin-bottom: 20px; }}
|
26 |
-
th, td {{ border: 1px solid #ccc; padding: 8px; text-align: left; }}
|
27 |
-
th {{ background-color: #f9f9f9; }}
|
28 |
-
ul {{ list-style: none; padding-left: 0; }}
|
29 |
-
li::before {{ content: "\\2713 "; color: green; margin-right: 6px; }}
|
30 |
-
li.missing::before {{ content: "\\2717 "; color: red; }}
|
31 |
-
details {{ margin-top: 20px; }}
|
32 |
-
pre {{ background-color: #f4f4f4; padding: 10px; border-radius: 4px; }}
|
33 |
-
</style>
|
34 |
-
</head>
|
35 |
-
<body>
|
36 |
-
<h2>AIBOM Completeness Score: <strong>{score_report['total_score']}/{total_max}</strong></h2>
|
37 |
-
<h3>Section Scores</h3>
|
38 |
-
<table>
|
39 |
-
<tr><th>Section</th><th>Score</th></tr>
|
40 |
-
"""
|
41 |
-
for section, score in score_report.get("section_scores", {}).items():
|
42 |
-
max_score = max_scores.get(section, 0)
|
43 |
-
html += f"<tr><td>{humanize(section)}</td><td>{score}/{max_score}</td></tr>"
|
44 |
-
|
45 |
-
html += "</table>"
|
46 |
-
|
47 |
-
if "field_checklist" in score_report:
|
48 |
-
html += "<h3>Field Checklist</h3><ul>"
|
49 |
-
for field, mark in score_report["field_checklist"].items():
|
50 |
-
css_class = "missing" if mark == "✘" else ""
|
51 |
-
html += f"<li class=\"{css_class}\">{field}</li>"
|
52 |
-
html += "</ul>"
|
53 |
-
|
54 |
-
html += f"""
|
55 |
-
<details>
|
56 |
-
<summary>Raw Score Report</summary>
|
57 |
-
<pre>{json.dumps(score_report, indent=2)}</pre>
|
58 |
-
</details>
|
59 |
-
</body>
|
60 |
-
</html>
|
61 |
-
"""
|
62 |
-
return html
|
63 |
-
|
64 |
-
def save_score_report_html(score_report: Dict[str, any], output_path: str):
|
65 |
-
html_content = render_score_html(score_report)
|
66 |
-
with open(output_path, 'w', encoding='utf-8') as f:
|
67 |
-
f.write(html_content)
|
68 |
-
print(f"Score report saved to {output_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|