HarshitaSuri's picture
Update app.py
e4c14aa verified
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()