Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import AutoImageProcessor, SiglipForImageClassification | |
from PIL import Image | |
import torch | |
import cv2 | |
import os | |
import uuid | |
# Load model | |
model_name = "prithivMLmods/deepfake-detector-model-v1" | |
processor = AutoImageProcessor.from_pretrained(model_name) | |
model = SiglipForImageClassification.from_pretrained(model_name) | |
def analyze_video(video_path): | |
cap = cv2.VideoCapture(video_path) | |
result_labels = [] | |
frame_skip = 10 | |
count = 0 | |
while True: | |
ret, frame = cap.read() | |
if not ret: | |
break | |
if count % frame_skip == 0: | |
try: | |
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
pil = Image.fromarray(rgb) | |
inputs = processor(images=pil, return_tensors="pt") | |
with torch.no_grad(): | |
logits = model(**inputs).logits | |
pred = torch.argmax(logits, dim=1).item() | |
label = model.config.id2label[pred] | |
result_labels.append(label) | |
except: | |
continue | |
count += 1 | |
cap.release() | |
real = result_labels.count("REAL") | |
fake = result_labels.count("FAKE") | |
final = "REAL" if real > fake else "FAKE" | |
return f"π’ REAL frames: {real} | π΄ FAKE frames: {fake} β Final verdict: **{final}**" | |
# Gradio interface | |
demo = gr.Interface( | |
fn=analyze_video, | |
inputs=gr.Video(label="Upload a video"), | |
outputs=gr.Markdown(label="Result"), | |
title="π Deepfake Video Detector", | |
description="Upload a video (MP4). The model will analyze it and return whether it's REAL or FAKE based on detected face frames." | |
) | |
demo.launch() | |