Spaces:
Running
Running
Update src/aibom_generator/generator.py
Browse files
src/aibom_generator/generator.py
CHANGED
@@ -119,14 +119,20 @@ class AIBOMGenerator:
|
|
119 |
metadata["ai:task"] = metadata.get("pipeline_tag", "Text Generation")
|
120 |
metadata["ai:framework"] = "PyTorch" if "transformers" in metadata.get("library_name", "") else "Unknown"
|
121 |
|
122 |
-
|
123 |
return {k: v for k, v in metadata.items() if v is not None}
|
124 |
|
125 |
def _extract_unstructured_metadata(self, model_card: ModelCard) -> Dict[str, Any]:
|
126 |
return {}
|
127 |
|
128 |
def _create_metadata_section(self, model_id: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
129 |
-
aibom_stub = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
score_report = calculate_completeness_score(aibom_stub)
|
131 |
|
132 |
timestamp = datetime.datetime.utcnow().isoformat() + "Z"
|
@@ -156,10 +162,8 @@ class AIBOMGenerator:
|
|
156 |
value = json.dumps(value)
|
157 |
properties.append({"name": key, "value": str(value)})
|
158 |
|
159 |
-
# Add quality scoring results
|
160 |
properties.append({"name": "aibom:quality-score", "value": str(score_report["total_score"])})
|
161 |
properties.append({"name": "aibom:quality-breakdown", "value": json.dumps(score_report["section_scores"])})
|
162 |
-
properties.append({"name": "aibom:field-checklist", "value": json.dumps(score_report["field_checklist"])})
|
163 |
|
164 |
metadata_section = {
|
165 |
"timestamp": timestamp,
|
@@ -222,14 +226,4 @@ class AIBOMGenerator:
|
|
222 |
if considerations:
|
223 |
model_card_section["considerations"] = considerations
|
224 |
|
225 |
-
properties = []
|
226 |
-
for key, value in metadata.items():
|
227 |
-
if key not in ["name", "author", "license", "base_model", "library_name", "pipeline_tag", "eval_results", "limitations", "ethical_considerations", "bias", "risks"]:
|
228 |
-
if isinstance(value, (list, dict)):
|
229 |
-
value = json.dumps(value)
|
230 |
-
properties.append({"name": key, "value": str(value)})
|
231 |
-
|
232 |
-
if properties:
|
233 |
-
model_card_section["properties"] = properties
|
234 |
-
|
235 |
return model_card_section
|
|
|
119 |
metadata["ai:task"] = metadata.get("pipeline_tag", "Text Generation")
|
120 |
metadata["ai:framework"] = "PyTorch" if "transformers" in metadata.get("library_name", "") else "Unknown"
|
121 |
|
|
|
122 |
return {k: v for k, v in metadata.items() if v is not None}
|
123 |
|
124 |
def _extract_unstructured_metadata(self, model_card: ModelCard) -> Dict[str, Any]:
|
125 |
return {}
|
126 |
|
127 |
def _create_metadata_section(self, model_id: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
128 |
+
aibom_stub = {
|
129 |
+
"bomFormat": "CycloneDX",
|
130 |
+
"specVersion": "1.6",
|
131 |
+
"serialNumber": f"urn:uuid:{str(uuid.uuid4())}",
|
132 |
+
"version": 1,
|
133 |
+
"metadata": {},
|
134 |
+
"components": [self._create_component_section(model_id, metadata)]
|
135 |
+
}
|
136 |
score_report = calculate_completeness_score(aibom_stub)
|
137 |
|
138 |
timestamp = datetime.datetime.utcnow().isoformat() + "Z"
|
|
|
162 |
value = json.dumps(value)
|
163 |
properties.append({"name": key, "value": str(value)})
|
164 |
|
|
|
165 |
properties.append({"name": "aibom:quality-score", "value": str(score_report["total_score"])})
|
166 |
properties.append({"name": "aibom:quality-breakdown", "value": json.dumps(score_report["section_scores"])})
|
|
|
167 |
|
168 |
metadata_section = {
|
169 |
"timestamp": timestamp,
|
|
|
226 |
if considerations:
|
227 |
model_card_section["considerations"] = considerations
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
return model_card_section
|