Spaces:
Running
on
Zero
Running
on
Zero
Update deepfake_vs_real.py
Browse files- deepfake_vs_real.py +10 -15
deepfake_vs_real.py
CHANGED
@@ -1,14 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
from transformers import SiglipForImageClassification
|
4 |
-
from transformers.image_utils import load_image
|
5 |
from PIL import Image
|
6 |
import torch
|
7 |
|
8 |
-
# Load model and processor
|
9 |
-
model_name = "prithivMLmods/
|
10 |
-
model =
|
11 |
-
processor =
|
12 |
|
13 |
def deepfake_classification(image):
|
14 |
"""Predicts whether an image is a Deepfake or Real."""
|
@@ -18,20 +16,17 @@ def deepfake_classification(image):
|
|
18 |
with torch.no_grad():
|
19 |
outputs = model(**inputs)
|
20 |
logits = outputs.logits
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
}
|
26 |
-
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
27 |
-
|
28 |
-
return predictions
|
29 |
|
30 |
# Create Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
fn=deepfake_classification,
|
33 |
inputs=gr.Image(type="numpy"),
|
34 |
-
outputs=gr.Label(label="Prediction
|
35 |
title="Deepfake vs. Real Image Classification",
|
36 |
description="Upload an image to determine if it's a Deepfake or a Real one."
|
37 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import ViTForImageClassification, ViTImageProcessor
|
|
|
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
|
6 |
+
# Load the model and processor
|
7 |
+
model_name = "prithivMLmods/Deep-Fake-Detector-v2-Model"
|
8 |
+
model = ViTForImageClassification.from_pretrained(model_name)
|
9 |
+
processor = ViTImageProcessor.from_pretrained(model_name)
|
10 |
|
11 |
def deepfake_classification(image):
|
12 |
"""Predicts whether an image is a Deepfake or Real."""
|
|
|
16 |
with torch.no_grad():
|
17 |
outputs = model(**inputs)
|
18 |
logits = outputs.logits
|
19 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
20 |
|
21 |
+
# Get label mapping
|
22 |
+
label = model.config.id2label[predicted_class] if hasattr(model.config, "id2label") else str(predicted_class)
|
23 |
+
return {label: 1.0} # Gradio Label output expects a dictionary
|
|
|
|
|
|
|
24 |
|
25 |
# Create Gradio interface
|
26 |
iface = gr.Interface(
|
27 |
fn=deepfake_classification,
|
28 |
inputs=gr.Image(type="numpy"),
|
29 |
+
outputs=gr.Label(label="Prediction"),
|
30 |
title="Deepfake vs. Real Image Classification",
|
31 |
description="Upload an image to determine if it's a Deepfake or a Real one."
|
32 |
)
|