Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,271 Bytes
91f05e0 2727aef 91f05e0 2727aef 91f05e0 2727aef 91f05e0 2727aef 91f05e0 2727aef 91f05e0 2727aef 91f05e0 2727aef 91f05e0 |
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 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
import spaces
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch
# Load model and processor
model_name = "prithivMLmods/Deepfake-Detect-Siglip2"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
@spaces.GPU
def deepfake_detection(image):
"""Classifies an image as Fake or Real."""
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
labels = model.config.id2label
predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
return predictions
# Create Gradio interface
iface = gr.Interface(
fn=deepfake_detection,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(label="Detection Result"),
title="Deepfake Detection Model",
description="Upload an image to determine if it is Fake or Real."
)
# Launch the app
if __name__ == "__main__":
iface.launch() |