import os import gradio as gr import json # Since this is running in Hugging Face Spaces, we'll assume the detection logic # needs to be implemented here or use a simpler demo version def detect(image): """Detect deepfake content in an image with comprehensive error handling""" if image is None: raise gr.Error("Please upload an image to analyze") try: # Mock detection logic (replace with actual model inference if available) # In a real implementation, you'd load your model here import random overall_score = random.uniform(60, 99) aigen_score = random.uniform(0, 100) deepfake_score = random.uniform(0, 100) overall = f"{overall_score:.1f}% Confidence" aigen = f"{aigen_score:.1f}% (AI-Generated Content Likelihood)" deepfake = f"{deepfake_score:.1f}% (Face Manipulation Likelihood)" return overall, aigen, deepfake except Exception as e: raise gr.Error(f"Analysis error: {str(e)}") # Custom CSS remains the same custom_css = """ .container { max-width: 1200px; margin: 0 auto; padding: 20px; font-family: 'Arial', sans-serif; } .header { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px; } .button-gradient { background: linear-gradient(45deg, #3498db, #2ecc71, #9b59b6); background-size: 400% 400%; border: none; padding: 12px 24px; font-size: 16px; font-weight: 600; color: white; border-radius: 8px; cursor: pointer; transition: all 0.3s ease; animation: gradientAnimation 3s ease infinite; box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3); } .button-gradient:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(52, 152, 219, 0.5); } @keyframes gradientAnimation { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } """ MARKDOWN0 = """

DeepFake Detection System

Advanced AI-powered analysis for identifying manipulated media

""" with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo: gr.Markdown(MARKDOWN0) with gr.Row(elem_classes="container"): with gr.Column(scale=1): image = gr.Image(type='filepath', height=400, label="Upload Image") detect_button = gr.Button("Analyze Image", elem_classes="button-gradient") with gr.Column(scale=2): overall = gr.Label(label="Confidence Score") aigen = gr.Label(label="AI-Generated Content") deepfake = gr.Label(label="Face Manipulation") detect_button.click( fn=detect, inputs=[image], outputs=[overall, aigen, deepfake] ) # Launch configuration optimized for Hugging Face Spaces demo.launch( debug=True )