Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,30 @@
|
|
1 |
-
import
|
2 |
-
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
3 |
from PIL import Image
|
|
|
4 |
import torch
|
5 |
|
6 |
-
#
|
7 |
-
model_name = "
|
8 |
-
model = AutoModelForImageClassification.from_pretrained(model_name)
|
9 |
processor = AutoImageProcessor.from_pretrained(model_name)
|
|
|
10 |
|
11 |
def detect_deepfake(image):
|
12 |
-
|
13 |
inputs = processor(images=image, return_tensors="pt")
|
14 |
with torch.no_grad():
|
15 |
outputs = model(**inputs)
|
16 |
-
probs = torch.nn.functional.softmax(outputs.logits, dim
|
|
|
|
|
17 |
|
18 |
-
# Convert to dict
|
19 |
-
labels = model.config.id2label
|
20 |
-
results = {labels[i]: float(probs[i]) for i in range(len(labels))}
|
21 |
-
return results
|
22 |
-
|
23 |
-
# Gradio UI
|
24 |
demo = gr.Interface(
|
25 |
fn=detect_deepfake,
|
26 |
-
inputs=gr.Image(type="
|
27 |
outputs=gr.Label(num_top_classes=2),
|
28 |
title="Deepfake Detector",
|
29 |
-
description="Upload an image
|
30 |
)
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
demo.launch()
|
|
|
|
1 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
|
|
2 |
from PIL import Image
|
3 |
+
import gradio as gr
|
4 |
import torch
|
5 |
|
6 |
+
# New model details
|
7 |
+
model_name = "prithivMLmods/deepfake-detector-model-v1"
|
|
|
8 |
processor = AutoImageProcessor.from_pretrained(model_name)
|
9 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
10 |
|
11 |
def detect_deepfake(image):
|
12 |
+
image = Image.fromarray(image).convert("RGB")
|
13 |
inputs = processor(images=image, return_tensors="pt")
|
14 |
with torch.no_grad():
|
15 |
outputs = model(**inputs)
|
16 |
+
probs = torch.nn.functional.softmax(outputs.logits, dim=1)[0]
|
17 |
+
id2label = { "0": "Fake", "1": "Real" }
|
18 |
+
return { id2label[str(i)]: float(probs[i]) for i in range(2) }
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
demo = gr.Interface(
|
21 |
fn=detect_deepfake,
|
22 |
+
inputs=gr.Image(type="numpy"),
|
23 |
outputs=gr.Label(num_top_classes=2),
|
24 |
title="Deepfake Detector",
|
25 |
+
description="Upload an image; this model predicts Real vs Fake."
|
26 |
)
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
demo.launch()
|
30 |
+
|