Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
print(f"Prediction: Real={real_prob:.4f}, Fake={fake_prob:.4f}")
|
| 31 |
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import ViTForImageClassification, ViTImageProcessor
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
MODEL_NAME = "prithivMLmods/Deep-Fake-Detector-v2-Model"
|
| 7 |
+
|
| 8 |
+
processor = ViTImageProcessor.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = ViTForImageClassification.from_pretrained(MODEL_NAME)
|
| 10 |
+
|
| 11 |
+
def classify_image(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 |
+
labels = model.config.id2label
|
| 18 |
+
return { labels[i]: float(probs[i]) for i in range(len(probs)) }
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=classify_image,
|
| 22 |
+
inputs=gr.Image(type="numpy"),
|
| 23 |
+
outputs=gr.Label(num_top_classes=2, label="Prediction (Real vs Deepfake)"),
|
| 24 |
+
title="Deepfake Detector (ViT)",
|
| 25 |
+
description="Upload an image — model classifies it as Real or Deepfake."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|
|
|
|
|
|
|
| 30 |
|