Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,9 @@ logger = logging.getLogger(__name__)
|
|
12 |
model = ViTForImageClassification.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
13 |
processor = ViTImageProcessor.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
14 |
|
|
|
|
|
|
|
15 |
def detect(image, confidence_threshold=0.5):
|
16 |
"""Detect deepfake content using prithivMLmods/Deep-Fake-Detector-Model"""
|
17 |
if image is None:
|
@@ -34,18 +37,26 @@ def detect(image, confidence_threshold=0.5):
|
|
34 |
probabilities = torch.softmax(logits, dim=1)[0]
|
35 |
|
36 |
# Get confidence scores
|
37 |
-
confidence_real = probabilities[0].item() * 100
|
38 |
-
confidence_fake = probabilities[1].item() * 100
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
confidence_score = max(confidence_real, confidence_fake)
|
43 |
|
44 |
-
# Log
|
45 |
-
logger.info(f"
|
|
|
|
|
|
|
46 |
|
47 |
# Prepare output
|
48 |
-
overall = f"{confidence_score:.1f}% Confidence ({
|
49 |
aigen = f"{confidence_fake:.1f}% (AI-Generated Content Likelihood)"
|
50 |
deepfake = f"{confidence_fake:.1f}% (Face Manipulation Likelihood)"
|
51 |
|
@@ -98,7 +109,7 @@ MARKDOWN0 = """
|
|
98 |
<h1>DeepFake Detection System</h1>
|
99 |
<p>Advanced AI-powered analysis for identifying manipulated media<br>
|
100 |
Powered by prithivMLmods/Deep-Fake-Detector-Model (Updated Jan 2025)<br>
|
101 |
-
|
102 |
</div>
|
103 |
"""
|
104 |
|
|
|
12 |
model = ViTForImageClassification.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
13 |
processor = ViTImageProcessor.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
14 |
|
15 |
+
# Log model configuration to verify label mapping
|
16 |
+
logger.info(f"Model label mapping: {model.config.id2label}")
|
17 |
+
|
18 |
def detect(image, confidence_threshold=0.5):
|
19 |
"""Detect deepfake content using prithivMLmods/Deep-Fake-Detector-Model"""
|
20 |
if image is None:
|
|
|
37 |
probabilities = torch.softmax(logits, dim=1)[0]
|
38 |
|
39 |
# Get confidence scores
|
40 |
+
confidence_real = probabilities[0].item() * 100 # Assuming 0 is Real
|
41 |
+
confidence_fake = probabilities[1].item() * 100 # Assuming 1 is Fake
|
42 |
+
|
43 |
+
# Verify label mapping from model config
|
44 |
+
id2label = model.config.id2label
|
45 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
46 |
+
predicted_label = id2label[predicted_class]
|
47 |
|
48 |
+
# Adjust prediction based on threshold and label
|
49 |
+
threshold_predicted = "Fake" if confidence_fake / 100 >= confidence_threshold else "Real"
|
50 |
confidence_score = max(confidence_real, confidence_fake)
|
51 |
|
52 |
+
# Log detailed output
|
53 |
+
logger.info(f"Logits: {logits.tolist()}")
|
54 |
+
logger.info(f"Probabilities - Real: {confidence_real:.1f}%, Fake: {confidence_fake:.1f}%")
|
55 |
+
logger.info(f"Predicted Class: {predicted_class}, Label: {predicted_label}")
|
56 |
+
logger.info(f"Threshold ({confidence_threshold}): {threshold_predicted}")
|
57 |
|
58 |
# Prepare output
|
59 |
+
overall = f"{confidence_score:.1f}% Confidence ({threshold_predicted})"
|
60 |
aigen = f"{confidence_fake:.1f}% (AI-Generated Content Likelihood)"
|
61 |
deepfake = f"{confidence_fake:.1f}% (Face Manipulation Likelihood)"
|
62 |
|
|
|
109 |
<h1>DeepFake Detection System</h1>
|
110 |
<p>Advanced AI-powered analysis for identifying manipulated media<br>
|
111 |
Powered by prithivMLmods/Deep-Fake-Detector-Model (Updated Jan 2025)<br>
|
112 |
+
Adjust threshold to tune sensitivity; check logs for detailed output</p>
|
113 |
</div>
|
114 |
"""
|
115 |
|