Spaces:
Sleeping
Sleeping
from transformers import AutoImageProcessor, SiglipForImageClassification | |
from PIL import Image | |
import gradio as gr | |
import torch | |
# New model details | |
model_name = "prithivMLmods/deepfake-detector-model-v1" | |
processor = AutoImageProcessor.from_pretrained(model_name) | |
model = SiglipForImageClassification.from_pretrained(model_name) | |
def detect_deepfake(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] | |
id2label = { "0": "Fake", "1": "Real" } | |
return { id2label[str(i)]: float(probs[i]) for i in range(2) } | |
demo = gr.Interface( | |
fn=detect_deepfake, | |
inputs=gr.Image(type="numpy"), | |
outputs=gr.Label(num_top_classes=2), | |
title="Deepfake Detector", | |
description="Upload an image; this model predicts Real vs Fake." | |
) | |
if __name__ == "__main__": | |
demo.launch() | |