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

fix(deploy): enforce memory-safe spatial-FFT deepfake detector in containers to prevent 512MB OOM crash

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -0
  2. app/deepfake/classifier.py +19 -0
  3. chain/blockchain.json +150 -0
Dockerfile CHANGED
@@ -4,6 +4,8 @@ WORKDIR /app
4
 
5
  # Suppress pip root user warnings in Docker
6
  ENV PIP_ROOT_USER_ACTION=ignore
 
 
7
 
8
  # Install system dependencies for OpenCV and networking
9
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
4
 
5
  # Suppress pip root user warnings in Docker
6
  ENV PIP_ROOT_USER_ACTION=ignore
7
+ # Memory-conserving mode for cloud free tier containers (<= 512MB RAM)
8
+ ENV ENABLE_VIT_MODEL=false
9
 
10
  # Install system dependencies for OpenCV and networking
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
app/deepfake/classifier.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import logging
2
  from pathlib import Path
3
  from typing import Union, Dict, Any, Optional
@@ -26,6 +27,24 @@ class DeepfakeClassifier:
26
  if self._load_attempted:
27
  return
28
  self._load_attempted = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  try:
30
  from transformers import AutoImageProcessor, AutoModelForImageClassification
31
  import torch
 
1
+ import os
2
  import logging
3
  from pathlib import Path
4
  from typing import Union, Dict, Any, Optional
 
27
  if self._load_attempted:
28
  return
29
  self._load_attempted = True
30
+
31
+ # Memory conservation safeguard for cloud free tiers (e.g. Render 512MB RAM)
32
+ enable_vit = os.getenv("ENABLE_VIT_MODEL", "").lower()
33
+ if enable_vit == "false":
34
+ logger.info("ViT model disabled via ENABLE_VIT_MODEL=false. Using lightweight spatial-FFT detector.")
35
+ self._available = False
36
+ return
37
+ elif enable_vit != "true":
38
+ try:
39
+ import psutil
40
+ total_mb = psutil.virtual_memory().total / (1024 * 1024)
41
+ if total_mb < 1200:
42
+ logger.info("Host memory is %.0f MB (< 1200 MB). Using lightweight spatial-FFT detector to protect container stability.", total_mb)
43
+ self._available = False
44
+ return
45
+ except Exception:
46
+ pass
47
+
48
  try:
49
  from transformers import AutoImageProcessor, AutoModelForImageClassification
50
  import torch
chain/blockchain.json CHANGED
@@ -1231,5 +1231,155 @@
1231
  },
1232
  "previous_hash": "f0b09b09a2d9c870c18c19f4150c556b69837f1ab2355d125250e7eeb4811a11",
1233
  "hash": "79b0ecb7accd2580888ccb491311fae5d2df03d226addcacf1b3b6833179319d"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1234
  }
1235
  ]
 
1231
  },
1232
  "previous_hash": "f0b09b09a2d9c870c18c19f4150c556b69837f1ab2355d125250e7eeb4811a11",
1233
  "hash": "79b0ecb7accd2580888ccb491311fae5d2df03d226addcacf1b3b6833179319d"
1234
+ },
1235
+ {
1236
+ "index": 11,
1237
+ "timestamp": 1788773609.0568485,
1238
+ "evidence_record": {
1239
+ "schema_version": "2.0",
1240
+ "protocol": "FaceID forensic evidence",
1241
+ "created_at": "2026-09-07T09:33:29.056289+00:00",
1242
+ "source_image": {
1243
+ "filename": "sample.jpg",
1244
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1245
+ "phash": "e959968619697996"
1246
+ },
1247
+ "image": {
1248
+ "filename": "sample.jpg",
1249
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1250
+ "phash": "e959968619697996"
1251
+ },
1252
+ "biometrics": {
1253
+ "detected": false,
1254
+ "face_count": 0,
1255
+ "embedding_model": "ArcFace 512-d (buffalo_s)",
1256
+ "embedding_persistent": false,
1257
+ "det_score": 0.0,
1258
+ "face_boxes": [],
1259
+ "landmarks": []
1260
+ },
1261
+ "face": {
1262
+ "detected": false,
1263
+ "count": 0,
1264
+ "embedding_generated": false,
1265
+ "det_score": 0.0,
1266
+ "face_boxes": [],
1267
+ "landmarks": []
1268
+ },
1269
+ "osint_search": {
1270
+ "provider": "SerpApi Google Lens",
1271
+ "total_candidates": 2,
1272
+ "error": null
1273
+ },
1274
+ "reverse_search": {
1275
+ "provider": "SerpApi Google Lens",
1276
+ "count": 2,
1277
+ "error": null
1278
+ },
1279
+ "best_match": {
1280
+ "title": "Rolling into a new era! Once Upon A KATAMARI out NOW on ...",
1281
+ "source": "Instagram",
1282
+ "link": "https://www.instagram.com/p/DQK_wc9iaHM/",
1283
+ "platform": "Instagram",
1284
+ "is_specific_post": true,
1285
+ "post_type": "Post",
1286
+ "cosine_similarity": null,
1287
+ "visual_similarity": 0.3658,
1288
+ "phash_distance": 28,
1289
+ "verified": false
1290
+ },
1291
+ "deepfake_analysis": {
1292
+ "label": "Deepfake",
1293
+ "risk_score": 0.6974,
1294
+ "confidence": 0.6974,
1295
+ "is_synthetic": true,
1296
+ "model": "prithivMLmods/Deep-Fake-Detector-v2-Model",
1297
+ "status": "ANALYZED"
1298
+ },
1299
+ "verification": {
1300
+ "status": "NO_CONFIRMED_MATCH",
1301
+ "best_similarity": 0.3658,
1302
+ "threshold": 0.9,
1303
+ "phash_max_distance": 12
1304
+ },
1305
+ "evidence_hash": "e25c3beaad64c475b3d01776509999fd392bb2f4477d9b6fe0a1d2568a863344"
1306
+ },
1307
+ "previous_hash": "79b0ecb7accd2580888ccb491311fae5d2df03d226addcacf1b3b6833179319d",
1308
+ "hash": "ac012e7f1e6c3fe32f37621d492d30106d321b7fd44680b41c5fbb00037bbb65"
1309
+ },
1310
+ {
1311
+ "index": 12,
1312
+ "timestamp": 1788773744.7905204,
1313
+ "evidence_record": {
1314
+ "schema_version": "2.0",
1315
+ "protocol": "FaceID forensic evidence",
1316
+ "created_at": "2026-09-07T09:35:44.790021+00:00",
1317
+ "source_image": {
1318
+ "filename": "sample.jpg",
1319
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1320
+ "phash": "e959968619697996"
1321
+ },
1322
+ "image": {
1323
+ "filename": "sample.jpg",
1324
+ "sha256": "954419c50ed11c9db3bd5453548eb1a2c39a967bfdc78dfc9e4f45a034d0ea3d",
1325
+ "phash": "e959968619697996"
1326
+ },
1327
+ "biometrics": {
1328
+ "detected": false,
1329
+ "face_count": 0,
1330
+ "embedding_model": "ArcFace 512-d (buffalo_s)",
1331
+ "embedding_persistent": false,
1332
+ "det_score": 0.0,
1333
+ "face_boxes": [],
1334
+ "landmarks": []
1335
+ },
1336
+ "face": {
1337
+ "detected": false,
1338
+ "count": 0,
1339
+ "embedding_generated": false,
1340
+ "det_score": 0.0,
1341
+ "face_boxes": [],
1342
+ "landmarks": []
1343
+ },
1344
+ "osint_search": {
1345
+ "provider": "SerpApi Google Lens",
1346
+ "total_candidates": 2,
1347
+ "error": null
1348
+ },
1349
+ "reverse_search": {
1350
+ "provider": "SerpApi Google Lens",
1351
+ "count": 2,
1352
+ "error": null
1353
+ },
1354
+ "best_match": {
1355
+ "title": "MANGORO - YouTube",
1356
+ "source": "YouTube",
1357
+ "link": "https://www.youtube.com/@mangoro_official",
1358
+ "platform": "YouTube",
1359
+ "is_specific_post": false,
1360
+ "post_type": "Generic Portal / Aggregator",
1361
+ "cosine_similarity": null,
1362
+ "visual_similarity": 0.4478,
1363
+ "phash_distance": 20,
1364
+ "verified": false
1365
+ },
1366
+ "deepfake_analysis": {
1367
+ "label": "Authentic / Real",
1368
+ "risk_score": 0.05,
1369
+ "confidence": 0.9,
1370
+ "is_synthetic": false,
1371
+ "model": "Spatial-FFT-Heuristic (Offline Fallback)",
1372
+ "status": "ANALYZED"
1373
+ },
1374
+ "verification": {
1375
+ "status": "NO_CONFIRMED_MATCH",
1376
+ "best_similarity": 0.4478,
1377
+ "threshold": 0.9,
1378
+ "phash_max_distance": 12
1379
+ },
1380
+ "evidence_hash": "bffde6f891773c39da9467c1014ac596011dda1a5e282d7f2773fe8bb6c89e9d"
1381
+ },
1382
+ "previous_hash": "ac012e7f1e6c3fe32f37621d492d30106d321b7fd44680b41c5fbb00037bbb65",
1383
+ "hash": "2811693115f654795b8edbe36cbdd57e20dd75c4e30fb679adade8062a4e3373"
1384
  }
1385
  ]