Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- api/main.py +2 -2
- api/schemas.py +2 -2
- app.py +1 -1
- src/graph.py +26 -13
api/main.py
CHANGED
|
@@ -181,7 +181,7 @@ async def inspect(
|
|
| 181 |
calibrated_score=result.calibrated_score,
|
| 182 |
score_std=result.score_std,
|
| 183 |
category=result.category,
|
| 184 |
-
|
| 185 |
heatmap_b64=result.heatmap_b64,
|
| 186 |
defect_crop_b64=result.defect_crop_b64,
|
| 187 |
depth_map_b64=result.depth_map_b64,
|
|
@@ -501,7 +501,7 @@ async def health():
|
|
| 501 |
|
| 502 |
return HealthResponse(
|
| 503 |
status="ok",
|
| 504 |
-
|
| 505 |
uptime_seconds=round(get_uptime(), 1),
|
| 506 |
index_sizes=index_status,
|
| 507 |
coreset_size=sum(
|
|
|
|
| 181 |
calibrated_score=result.calibrated_score,
|
| 182 |
score_std=result.score_std,
|
| 183 |
category=result.category,
|
| 184 |
+
version=MODEL_VERSION,
|
| 185 |
heatmap_b64=result.heatmap_b64,
|
| 186 |
defect_crop_b64=result.defect_crop_b64,
|
| 187 |
depth_map_b64=result.depth_map_b64,
|
|
|
|
| 501 |
|
| 502 |
return HealthResponse(
|
| 503 |
status="ok",
|
| 504 |
+
version=MODEL_VERSION,
|
| 505 |
uptime_seconds=round(get_uptime(), 1),
|
| 506 |
index_sizes=index_status,
|
| 507 |
coreset_size=sum(
|
api/schemas.py
CHANGED
|
@@ -22,7 +22,7 @@ class InspectResponse(BaseModel):
|
|
| 22 |
calibrated_score: float = Field(..., ge=0.0, le=1.0)
|
| 23 |
score_std: float
|
| 24 |
category: str
|
| 25 |
-
|
| 26 |
|
| 27 |
# Visuals (base64 PNG strings)
|
| 28 |
heatmap_b64: Optional[str] = None
|
|
@@ -116,7 +116,7 @@ class CorrectionResponse(BaseModel):
|
|
| 116 |
# ββ /health ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 117 |
class HealthResponse(BaseModel):
|
| 118 |
status: str
|
| 119 |
-
|
| 120 |
uptime_seconds: float
|
| 121 |
index_sizes: dict
|
| 122 |
coreset_size: int
|
|
|
|
| 22 |
calibrated_score: float = Field(..., ge=0.0, le=1.0)
|
| 23 |
score_std: float
|
| 24 |
category: str
|
| 25 |
+
version: str
|
| 26 |
|
| 27 |
# Visuals (base64 PNG strings)
|
| 28 |
heatmap_b64: Optional[str] = None
|
|
|
|
| 116 |
# ββ /health ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 117 |
class HealthResponse(BaseModel):
|
| 118 |
status: str
|
| 119 |
+
version: str
|
| 120 |
uptime_seconds: float
|
| 121 |
index_sizes: dict
|
| 122 |
coreset_size: int
|
app.py
CHANGED
|
@@ -101,7 +101,7 @@ def run_inspector(image, category_hint, last_click_state):
|
|
| 101 |
meta = (f"Category: {category} | "
|
| 102 |
f"Raw score: {result.get('anomaly_score', 0):.4f} | "
|
| 103 |
f"Latency: {latency:.0f}ms | "
|
| 104 |
-
f"Model: {result.get('
|
| 105 |
|
| 106 |
# Poll LLM report
|
| 107 |
report_id = result.get("report_id")
|
|
|
|
| 101 |
meta = (f"Category: {category} | "
|
| 102 |
f"Raw score: {result.get('anomaly_score', 0):.4f} | "
|
| 103 |
f"Latency: {latency:.0f}ms | "
|
| 104 |
+
f"Model: {result.get('version', 'v1.0')}")
|
| 105 |
|
| 106 |
# Poll LLM report
|
| 107 |
report_id = result.get("report_id")
|
src/graph.py
CHANGED
|
@@ -24,21 +24,34 @@ class KnowledgeGraph:
|
|
| 24 |
def load(self):
|
| 25 |
path = os.path.join(self.data_dir, "knowledge_graph.json")
|
| 26 |
if not os.path.exists(path):
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
with open(path) as f:
|
| 30 |
-
data = json.load(f)
|
| 31 |
-
|
| 32 |
-
# Handle both old and new NetworkX node-link formats
|
| 33 |
-
if "links" in data:
|
| 34 |
-
data["links"] = data.get("links", [])
|
| 35 |
try:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
print(f"Knowledge graph loaded: "
|
| 44 |
f"{self.graph.number_of_nodes()} nodes, "
|
|
|
|
| 24 |
def load(self):
|
| 25 |
path = os.path.join(self.data_dir, "knowledge_graph.json")
|
| 26 |
if not os.path.exists(path):
|
| 27 |
+
print(f"Warning: Knowledge graph not found at {path}, using empty graph")
|
| 28 |
+
self.graph = nx.DiGraph()
|
| 29 |
+
return
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
| 32 |
+
with open(path) as f:
|
| 33 |
+
data = json.load(f)
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Warning: Failed to load knowledge graph JSON: {e}")
|
| 36 |
+
self.graph = nx.DiGraph()
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
# Try standard NetworkX node_link_graph format (expects 'links' or 'edges')
|
| 40 |
+
try:
|
| 41 |
+
self.graph = nx.node_link_graph(data, directed=True)
|
| 42 |
+
except (KeyError, TypeError):
|
| 43 |
+
# If that fails, try converting 'edges' key to 'links'
|
| 44 |
+
if "edges" in data:
|
| 45 |
+
data["links"] = data.pop("edges")
|
| 46 |
+
try:
|
| 47 |
+
self.graph = nx.node_link_graph(data, directed=True)
|
| 48 |
+
except Exception as e:
|
| 49 |
+
print(f"Warning: Failed to load graph with edgesβlinks conversion: {e}")
|
| 50 |
+
self.graph = nx.DiGraph()
|
| 51 |
+
else:
|
| 52 |
+
# Last resort: create empty graph
|
| 53 |
+
print(f"Warning: Knowledge graph format not recognized, using empty graph")
|
| 54 |
+
self.graph = nx.DiGraph()
|
| 55 |
|
| 56 |
print(f"Knowledge graph loaded: "
|
| 57 |
f"{self.graph.number_of_nodes()} nodes, "
|