Spaces:
Running
on
Zero
Running
on
Zero
Update deepfake_vs_real.py
Browse files- deepfake_vs_real.py +15 -10
deepfake_vs_real.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
|
|
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
|
6 |
-
# Load
|
7 |
-
model_name = "prithivMLmods/
|
8 |
-
model =
|
9 |
-
processor =
|
10 |
|
11 |
def deepfake_classification(image):
|
12 |
"""Predicts whether an image is a Deepfake or Real."""
|
@@ -16,17 +18,20 @@ def deepfake_classification(image):
|
|
16 |
with torch.no_grad():
|
17 |
outputs = model(**inputs)
|
18 |
logits = outputs.logits
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
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 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoImageProcessor
|
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/Deepfake-vs-Real-8000"
|
10 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
11 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
12 |
|
13 |
def deepfake_classification(image):
|
14 |
"""Predicts whether an image is a Deepfake or Real."""
|
|
|
18 |
with torch.no_grad():
|
19 |
outputs = model(**inputs)
|
20 |
logits = outputs.logits
|
21 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
22 |
|
23 |
+
labels = {
|
24 |
+
"0": "Deepfake", "1": "Real one"
|
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 Scores"),
|
35 |
title="Deepfake vs. Real Image Classification",
|
36 |
description="Upload an image to determine if it's a Deepfake or a Real one."
|
37 |
)
|