File size: 1,536 Bytes
faa850e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
import gradio as gr
from PIL import Image
import random

def dummy_deepfake_detector(image: Image.Image, prompt: str) -> tuple[str, Image.Image, str]:
    """
    Simulates a deepfake detector. Replace this logic with your real model.
    """
    # Dummy logic: randomly decide real or fake
    prediction = random.choice(["Real", "Fake"])
    score = 1 if prediction == "Real" else 0  # Leaderboard dummy score
    return f"Prediction: {prediction}", image, f"You: {score} point{'s' if score != 1 else ''}"

with gr.Blocks() as demo:
    gr.Markdown("## Fool the Deepfake Detector")
    gr.Markdown("Upload an image and fool the deepfake detection model. Give it a try!")

    with gr.Row():
        prompt_input = gr.Textbox(
            label="Suggested prompt",
            placeholder="e.g., A portrait photograph of Barack Obama delivering a speech...",
            value="A portrait photograph of Barack Obama delivering a speech, with the United States flag in the background"
        )

    with gr.Row():
        image_input = gr.Image(type="pil", label="", tool=None)
        submit_btn = gr.Button("Upload")

    with gr.Row():
        prediction_output = gr.Text(label="Result")
        image_output = gr.Image(label="", show_label=False)
    
    leaderboard = gr.Text(label="Leaderboard")

    submit_btn.click(fn=dummy_deepfake_detector, 
                     inputs=[image_input, prompt_input],
                     outputs=[prediction_output, image_output, leaderboard])

if __name__ == "__main__":
    demo.launch()