File size: 1,210 Bytes
88b2a8e 40d5d60 dada46f 88b2a8e 0adc2a6 88b2a8e 0adc2a6 88b2a8e 40d5d60 0adc2a6 88b2a8e 0adc2a6 88b2a8e 0adc2a6 88b2a8e 0adc2a6 88b2a8e 0adc2a6 e4c14aa 88b2a8e 0adc2a6 88b2a8e e4c14aa 88b2a8e |
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 |
import gradio as gr
from transformers import pipeline
from PIL import Image
# Load the deepfake detection model
deepfake_detector = pipeline("image-classification", model="Wvolf/ViT_Deepfake_Detection")
def detect_deepfake(image):
result = deepfake_detector(image)
prediction = max(result, key=lambda x: x['score'])
label = prediction['label'].lower()
confidence = prediction['score'] * 100
# Adjusted threshold logic
if label == "fake" and confidence > 75:
verdict = f"🚨 Deepfake Detected! FAKE with {confidence:.2f}% confidence."
elif label == "real" and confidence > 75:
verdict = f"✅ REAL image with {confidence:.2f}% confidence."
else:
verdict = f"⚠️ Uncertain — low confidence: {label.upper()} with {confidence:.2f}% confidence."
return verdict
# Gradio UI — upload only (no webcam)
iface = gr.Interface(
fn=detect_deepfake,
inputs=gr.Image(type="pil", label="Upload an Image", sources=["upload"]),
outputs="text",
title="Deepfake Confidence Score Detector",
description="Upload an image to check if it's a deepfake. Powered by Hugging Face Transformers."
)
if __name__ == "__main__":
iface.launch()
|