File size: 1,000 Bytes
17f4543
 
5961733
e952c3e
 
17f4543
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5961733
1
2
3
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
31
import gradio as gr
from transformers import ViTForImageClassification, ViTImageProcessor
from PIL import Image
import torch

MODEL_NAME = "prithivMLmods/Deep-Fake-Detector-v2-Model"

processor = ViTImageProcessor.from_pretrained(MODEL_NAME)
model = ViTForImageClassification.from_pretrained(MODEL_NAME)

def classify_image(image):
    image = Image.fromarray(image).convert("RGB")
    inputs = processor(images=image, return_tensors="pt")
    with torch.no_grad():
        outputs = model(**inputs)
        probs = torch.nn.functional.softmax(outputs.logits, dim=-1)[0]
    labels = model.config.id2label
    return { labels[i]: float(probs[i]) for i in range(len(probs)) }

demo = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(num_top_classes=2, label="Prediction (Real vs Deepfake)"),
    title="Deepfake Detector (ViT)",
    description="Upload an image — model classifies it as Real or Deepfake."
)

if __name__ == "__main__":
    demo.launch()