Spaces:
Running
on
Zero
Running
on
Zero
Update deepfake_vs_real.py
Browse files- deepfake_vs_real.py +11 -11
deepfake_vs_real.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
import spaces
|
3 |
from transformers import AutoImageProcessor
|
4 |
from transformers import SiglipForImageClassification
|
5 |
from transformers.image_utils import load_image
|
@@ -7,13 +6,12 @@ from PIL import Image
|
|
7 |
import torch
|
8 |
|
9 |
# Load model and processor
|
10 |
-
model_name = "prithivMLmods/Deepfake-
|
11 |
model = SiglipForImageClassification.from_pretrained(model_name)
|
12 |
processor = AutoImageProcessor.from_pretrained(model_name)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
"""Classifies an image as Fake or Real."""
|
17 |
image = Image.fromarray(image).convert("RGB")
|
18 |
inputs = processor(images=image, return_tensors="pt")
|
19 |
|
@@ -22,18 +20,20 @@ def deepfake_detection(image):
|
|
22 |
logits = outputs.logits
|
23 |
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
24 |
|
25 |
-
labels =
|
26 |
-
|
|
|
|
|
27 |
|
28 |
return predictions
|
29 |
|
30 |
# Create Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
-
fn=
|
33 |
inputs=gr.Image(type="numpy"),
|
34 |
-
outputs=gr.Label(label="
|
35 |
-
title="Deepfake
|
36 |
-
description="Upload an image to determine if it
|
37 |
)
|
38 |
|
39 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoImageProcessor
|
3 |
from transformers import SiglipForImageClassification
|
4 |
from transformers.image_utils import load_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."""
|
|
|
15 |
image = Image.fromarray(image).convert("RGB")
|
16 |
inputs = processor(images=image, return_tensors="pt")
|
17 |
|
|
|
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 |
)
|
38 |
|
39 |
# Launch the app
|