rishik1111 commited on
Commit
fb6c3fc
·
1 Parent(s): a5c0306

feat(api): add /api/diagnose endpoint for cloud deployment telemetry

Browse files
Files changed (2) hide show
  1. app/server.py +49 -0
  2. chain/blockchain.json +75 -0
app/server.py CHANGED
@@ -54,6 +54,55 @@ def health_check():
54
  },
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  @app.post("/analyse")
58
  @app.post("/api/verify")
59
  async def analyse_image(
 
54
  },
55
  }
56
 
57
+ @app.get("/api/diagnose")
58
+ def diagnose_system():
59
+ diag = {}
60
+ try:
61
+ import psutil
62
+ mem = psutil.virtual_memory()
63
+ diag["memory_total_mb"] = round(mem.total / 1024 / 1024, 1)
64
+ diag["memory_available_mb"] = round(mem.available / 1024 / 1024, 1)
65
+ except Exception as e:
66
+ diag["memory_error"] = str(e)
67
+
68
+ diag["serpapi_configured"] = bool(os.getenv("SERPAPI_API_KEY") or os.getenv("SERPAPI_KEY"))
69
+ diag["sepolia_rpc_configured"] = bool(os.getenv("RPC_URL"))
70
+ diag["wallet_configured"] = bool(os.getenv("WALLET_ADDRESS"))
71
+ diag["private_key_configured"] = bool(os.getenv("PRIVATE_KEY"))
72
+
73
+ try:
74
+ import cv2
75
+ import numpy as np
76
+ dummy = np.zeros((100, 100, 3), dtype=np.uint8)
77
+ diag["opencv_numpy"] = "OK"
78
+ except Exception as e:
79
+ diag["opencv_numpy"] = str(e)
80
+
81
+ try:
82
+ valid, err = local_chain.is_valid_chain()
83
+ diag["blockchain"] = {"valid": valid, "length": len(local_chain), "err": err}
84
+ except Exception as e:
85
+ diag["blockchain_error"] = str(e)
86
+
87
+ try:
88
+ enc = pipeline.face_encoder
89
+ enc._load()
90
+ emb, info = enc.get_embedding(dummy)
91
+ diag["face_encoder"] = {"status": "OK", "model": enc.model_name, "info": info}
92
+ except Exception as e:
93
+ diag["face_encoder_error"] = str(e)
94
+
95
+ try:
96
+ df = pipeline.deepfake_classifier
97
+ from PIL import Image
98
+ pil_dummy = Image.fromarray(dummy)
99
+ res = df.analyze(pil_dummy)
100
+ diag["deepfake_classifier"] = {"status": "OK", "model": res.get("model")}
101
+ except Exception as e:
102
+ diag["deepfake_classifier_error"] = str(e)
103
+
104
+ return diag
105
+
106
  @app.post("/analyse")
107
  @app.post("/api/verify")
108
  async def analyse_image(
chain/blockchain.json CHANGED
@@ -1381,5 +1381,80 @@
1381
  },
1382
  "previous_hash": "ac012e7f1e6c3fe32f37621d492d30106d321b7fd44680b41c5fbb00037bbb65",
1383
  "hash": "2811693115f654795b8edbe36cbdd57e20dd75c4e30fb679adade8062a4e3373"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1384
  }
1385
  ]
 
1381
  },
1382
  "previous_hash": "ac012e7f1e6c3fe32f37621d492d30106d321b7fd44680b41c5fbb00037bbb65",
1383
  "hash": "2811693115f654795b8edbe36cbdd57e20dd75c4e30fb679adade8062a4e3373"
1384
+ },
1385
+ {
1386
+ "index": 13,
1387
+ "timestamp": 1788774588.1296272,
1388
+ "evidence_record": {
1389
+ "schema_version": "2.0",
1390
+ "protocol": "FaceID forensic evidence",
1391
+ "created_at": "2026-09-07T09:49:48.127567+00:00",
1392
+ "source_image": {
1393
+ "filename": "upload_01bb6fac.jpg",
1394
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1395
+ "phash": "e959968619697996"
1396
+ },
1397
+ "image": {
1398
+ "filename": "upload_01bb6fac.jpg",
1399
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1400
+ "phash": "e959968619697996"
1401
+ },
1402
+ "biometrics": {
1403
+ "detected": false,
1404
+ "face_count": 0,
1405
+ "embedding_model": "ArcFace 512-d (buffalo_s)",
1406
+ "embedding_persistent": false,
1407
+ "det_score": 0.0,
1408
+ "face_boxes": [],
1409
+ "landmarks": []
1410
+ },
1411
+ "face": {
1412
+ "detected": false,
1413
+ "count": 0,
1414
+ "embedding_generated": false,
1415
+ "det_score": 0.0,
1416
+ "face_boxes": [],
1417
+ "landmarks": []
1418
+ },
1419
+ "osint_search": {
1420
+ "provider": "SerpApi Google Lens",
1421
+ "total_candidates": 10,
1422
+ "error": null
1423
+ },
1424
+ "reverse_search": {
1425
+ "provider": "SerpApi Google Lens",
1426
+ "count": 10,
1427
+ "error": null
1428
+ },
1429
+ "best_match": {
1430
+ "title": "MANGORO - YouTube",
1431
+ "source": "YouTube",
1432
+ "link": "https://www.youtube.com/@mangoro_official",
1433
+ "platform": "YouTube",
1434
+ "is_specific_post": false,
1435
+ "post_type": "Generic Portal / Aggregator",
1436
+ "cosine_similarity": null,
1437
+ "visual_similarity": 0.4478,
1438
+ "phash_distance": 20,
1439
+ "verified": false
1440
+ },
1441
+ "deepfake_analysis": {
1442
+ "label": "Deepfake",
1443
+ "risk_score": 0.6974,
1444
+ "confidence": 0.6974,
1445
+ "is_synthetic": true,
1446
+ "model": "prithivMLmods/Deep-Fake-Detector-v2-Model",
1447
+ "status": "ANALYZED"
1448
+ },
1449
+ "verification": {
1450
+ "status": "NO_CONFIRMED_MATCH",
1451
+ "best_similarity": 0.4478,
1452
+ "threshold": 0.9,
1453
+ "phash_max_distance": 12
1454
+ },
1455
+ "evidence_hash": "443cf507dd180f41f22cd1890c3028dd73e3e0ff95b3a1218fb4f42dea1b47ed"
1456
+ },
1457
+ "previous_hash": "2811693115f654795b8edbe36cbdd57e20dd75c4e30fb679adade8062a4e3373",
1458
+ "hash": "05693381265418b356b4395c21757d4ad2b5302875f184193ea9b7066e6f033a"
1459
  }
1460
  ]