File size: 887 Bytes
59658d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
from PIL import Image

# Model ID from Hugging Face
MODEL_ID = "Ateeqq/ai-vs-human-image-detector"

# Load the pipeline
pipe = pipeline("image-classification", model=MODEL_ID)

def detect_ai_image(image: Image.Image):
    try:
        results = pipe(image)
        # Sort and take top results
        output = {r['label']: float(r['score']) for r in results}
        return output
    except Exception as e:
        return {"error": str(e)}

# Create Gradio interface
demo = gr.Interface(
    fn=detect_ai_image,
    inputs=gr.Image(type="pil", label="Upload an Image"),
    outputs=gr.Label(num_top_classes=2, label="Prediction"),
    title="AI vs Human Image Detector",
    description="Detect whether an image is AI-generated or human-made using the Ateeqq model.",
    theme="soft"
)

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