Ashish Ranjan Karn commited on
Commit
a304836
·
1 Parent(s): 3672bdc
Files changed (4) hide show
  1. .gitignore +65 -0
  2. README.md +51 -3
  3. app.py +81 -0
  4. requirements.txt +6 -0
.gitignore ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ MANIFEST
23
+
24
+ # PyTorch
25
+ *.pth
26
+ *.pt
27
+
28
+ # Jupyter Notebook
29
+ .ipynb_checkpoints
30
+
31
+ # IPython
32
+ profile_default/
33
+ ipython_config.py
34
+
35
+ # Environment variables
36
+ .env
37
+ .venv
38
+ env/
39
+ venv/
40
+ ENV/
41
+ env.bak/
42
+ venv.bak/
43
+
44
+ # IDE
45
+ .vscode/
46
+ .idea/
47
+ *.swp
48
+ *.swo
49
+ *~
50
+
51
+ # macOS
52
+ .DS_Store
53
+
54
+ # Windows
55
+ Thumbs.db
56
+ ehthumbs.db
57
+ Desktop.ini
58
+
59
+ # Model cache (optional - comment out if you want to cache models)
60
+ # .cache/
61
+ # models/
62
+
63
+ # Gradio temporary files
64
+ gradio_cached_examples/
65
+ flagged/
README.md CHANGED
@@ -1,12 +1,60 @@
1
  ---
2
- title: Ai Image Detector
3
- emoji: 🌖
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: AI Image Detector
3
+ emoji: 🤖
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # 🤖 AI Image Detector
14
+
15
+ Detect whether an image is AI-generated or real using state-of-the-art machine learning models.
16
+
17
+ ## Overview
18
+
19
+ This Gradio app uses the [Organika/sdxl-detector](https://huggingface.co/Organika/sdxl-detector) model to classify images as either AI-generated or real. The model has been specifically trained to detect images generated by various AI systems including:
20
+
21
+ - DALL-E
22
+ - Midjourney
23
+ - Stable Diffusion (SDXL)
24
+ - And other diffusion models
25
+
26
+ ## How to Use
27
+
28
+ 1. **Upload an Image**: Click on the upload area or drag and drop an image file (JPG, PNG, etc.)
29
+ 2. **Get Results**: The model will analyze your image and return probability scores
30
+ 3. **Interpret Results**: Higher probability for "AI-generated" suggests the image was created by AI
31
+
32
+ ## Model Information
33
+
34
+ - **Model**: [Organika/sdxl-detector](https://huggingface.co/Organika/sdxl-detector)
35
+ - **Task**: Image Classification (Binary: AI-generated vs Real)
36
+ - **Framework**: Transformers + PyTorch
37
+ - **Interface**: Gradio
38
+
39
+ ## Limitations
40
+
41
+ ⚠️ **Important Notes:**
42
+ - The model may not be 100% accurate on all images
43
+ - Performance may vary depending on the specific AI model used to generate the image
44
+ - Very high-quality AI images or heavily post-processed real images might be misclassified
45
+ - The model is primarily trained on SDXL-style generated images
46
+
47
+ ## Technical Details
48
+
49
+ The app uses both the Transformers pipeline and direct model inference to provide robust classification results. The model outputs probabilities for each class, giving you confidence scores for the prediction.
50
+
51
+ ## Development
52
+
53
+ This space is built with:
54
+ - **Gradio**: For the web interface
55
+ - **Transformers**: For model loading and inference
56
+ - **PyTorch**: As the backend framework
57
+
58
+ ---
59
+
60
+ *This is an educational tool for demonstrating AI image detection capabilities. Always use critical thinking when evaluating image authenticity.*
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
3
+
4
+ # Load the model and processor
5
+ print("Loading model...")
6
+ processor = AutoImageProcessor.from_pretrained("Organika/sdxl-detector")
7
+ model = AutoModelForImageClassification.from_pretrained("Organika/sdxl-detector")
8
+ pipe = pipeline("image-classification", model="Organika/sdxl-detector")
9
+ print("Model loaded successfully!")
10
+
11
+ def detect_ai(image):
12
+ """
13
+ Detect if an image is AI-generated or real.
14
+
15
+ Args:
16
+ image: PIL Image object
17
+
18
+ Returns:
19
+ dict: Probabilities for each class (AI-generated vs Real)
20
+ """
21
+ if image is None:
22
+ return {}
23
+
24
+ try:
25
+ # Pipeline result
26
+ pipe_out = pipe(image)
27
+
28
+ # Direct model inference for more detailed results
29
+ inputs = processor(images=image, return_tensors="pt")
30
+ outputs = model(**inputs)
31
+ logits = outputs.logits
32
+ probs = logits.softmax(dim=-1)[0].tolist()
33
+ id2label = model.config.id2label
34
+
35
+ # Create result dictionary
36
+ result = {
37
+ id2label[0]: probs[0],
38
+ id2label[1]: probs[1],
39
+ }
40
+
41
+ return result
42
+
43
+ except Exception as e:
44
+ print(f"Error processing image: {e}")
45
+ return {"Error": "Failed to process image"}
46
+
47
+ # Create the Gradio interface
48
+ demo = gr.Interface(
49
+ fn=detect_ai,
50
+ inputs=gr.Image(type="pil", label="Upload an Image"),
51
+ outputs=gr.Label(num_top_classes=2, label="AI vs Real Probability"),
52
+ title="🤖 AI‑Generated Image Detector",
53
+ description="""
54
+ Upload an image to detect whether it's AI-generated or real using the Organika/sdxl-detector model.
55
+
56
+ This model can help identify images generated by AI systems like DALL-E, Midjourney, Stable Diffusion, and others.
57
+
58
+ **How to use:**
59
+ 1. Upload an image (JPG, PNG, etc.)
60
+ 2. The model will analyze it and return probabilities
61
+ 3. Higher probability for "AI-generated" suggests the image was created by AI
62
+ """,
63
+ article="""
64
+ ### About the Model
65
+ This detector uses the [Organika/sdxl-detector](https://huggingface.co/Organika/sdxl-detector) model
66
+ to classify images as either AI-generated or real. The model has been trained to detect various AI-generated images
67
+ with a focus on SDXL and similar diffusion models.
68
+
69
+ ### Limitations
70
+ - The model may not be 100% accurate on all images
71
+ - Performance may vary depending on the AI model used to generate the image
72
+ - Very high-quality AI images or heavily post-processed real images might be misclassified
73
+ """,
74
+ examples=[
75
+ # You can add example images here if you have them
76
+ ],
77
+ cache_examples=False,
78
+ )
79
+
80
+ if __name__ == "__main__":
81
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ torchvision
4
+ gradio
5
+ Pillow
6
+ numpy