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