AIcoder35235 commited on
Commit
89f6876
·
verified ·
1 Parent(s): e9a0cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -64,24 +64,35 @@ def predict(req: PredictRequest):
64
  else:
65
  raise HTTPException(status_code=400, detail="Must provide 'image' (base64) or 'image_url'.")
66
 
 
67
  # 4. Execute AI Math
68
  results = pipe(img)
69
 
70
- # 5. Format to exact Task 25 specifications
71
- scores_dict = {}
72
- for res in results:
73
- raw_label = res['label'].upper()
74
- # Map standard model output to strict spec requirements
75
- final_label = "DEEPFAKE" if "FAKE" in raw_label else "REAL"
76
- scores_dict[final_label] = round(res['score'], 4)
77
-
78
- top_pred = max(scores_dict, key=scores_dict.get)
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  return {
81
  "prediction": top_pred,
82
- "confidence": scores_dict[top_pred],
83
- "scores": scores_dict
 
 
 
84
  }
85
-
86
  except Exception as e:
87
  raise HTTPException(status_code=400, detail=f"Failed to process face: {str(e)}")
 
64
  else:
65
  raise HTTPException(status_code=400, detail="Must provide 'image' (base64) or 'image_url'.")
66
 
67
+ # 4. Execute AI Math
68
  # 4. Execute AI Math
69
  results = pipe(img)
70
 
71
+ # 5. Sensitivity Logic (The Hackathon Fix)
72
+ # We manually check the fake score. If it's > 0.01, we flag it.
73
+ fake_score = 0.0
74
+ real_score = 0.0
 
 
 
 
 
75
 
76
+ for res in results:
77
+ if "FAKE" in res['label'].upper():
78
+ fake_score += res['score']
79
+ else:
80
+ real_score += res['score']
81
+
82
+ # THE FIX: Even if the AI says 90% Real, if it's 10% Fake, we flag it.
83
+ # This is a common strategy for detecting high-quality modern deepfakes.
84
+ if fake_score > 0.10: # Adjust this (0.01 to 0.10) to find the sweet spot
85
+ top_pred = "DEEPFAKE"
86
+ else:
87
+ top_pred = "REAL"
88
+
89
  return {
90
  "prediction": top_pred,
91
+ "confidence": round(max(fake_score, real_score), 4),
92
+ "scores": {
93
+ "REAL": round(real_score, 4),
94
+ "DEEPFAKE": round(fake_score, 4)
95
+ }
96
  }
 
97
  except Exception as e:
98
  raise HTTPException(status_code=400, detail=f"Failed to process face: {str(e)}")