File size: 3,351 Bytes
00ec010
ae6dd48
631ede9
868fc59
a143240
 
 
631ede9
868fc59
631ede9
 
 
 
3066f6d
631ede9
 
 
9d150e2
 
 
 
dd5cb06
a5b71d8
 
9d150e2
 
dd5cb06
9d150e2
dd5cb06
 
9d150e2
dd5cb06
9d150e2
 
dd5cb06
9d150e2
 
 
 
dd5cb06
 
3555163
dd5cb06
 
3555163
 
dd5cb06
 
9d150e2
dd5cb06
 
 
 
 
 
 
 
9d150e2
a5b71d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00ec010
 
 
3066f6d
 
00ec010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3066f6d
 
 
 
 
 
 
 
 
 
 
00ec010
ae6dd48
00ec010
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

---
language: en
tags:
  - image-classification
  - ai-detection
  - vit
license: mit
---

# AI Image Detector

## Model Description
This model is designed to detect whether an image is real or AI-generated. It uses Vision Transformer (ViT) architecture to provide accurate classification.

## Model Usage
```python
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import torch

# تحميل النموذج والمعالج
processor = ViTImageProcessor.from_pretrained("C:/Users/SUPREME TECH/Desktop/SAM3/ai-image-detector")
model = ViTForImageClassification.from_pretrained("C:/Users/SUPREME TECH/Desktop/SAM3/ai-image-detector")

def detect_image(image_path):
    # فتح وتجهيز الصورة
    image = Image.open(image_path)
    if image.mode != 'RGB':
        image = image.convert('RGB')
    
    # معالجة الصورة
    inputs = processor(images=image, return_tensors="pt")
    
    # الحصول على التنبؤات
    with torch.no_grad():
        outputs = model(**inputs)
        predictions = outputs.logits.softmax(dim=-1)
    
    # تحليل النتائج
    scores = predictions[0].tolist()
    results = [
        {"label": "REAL", "score": scores[0]},
        {"label": "FAKE", "score": scores[1]}
    ]
    
    # ترتيب النتائج حسب درجة الثقة
    results.sort(key=lambda x: x["score"], reverse=True)
    
    return {
        "prediction": results[0]["label"],
        "confidence": f"{results[0]['score']*100:.2f}%",
        "detailed_scores": [
            f"{r['label']}: {r['score']*100:.2f}%" 
            for r in results
        ]
    }

# كود للاختبار
if __name__ == "__main__":
    # يمكنك تغيير مسار الصورة هنا
    image_path = "path/to/your/image.jpg"
    
    try:
        result = detect_image(image_path)
        print("\nنتائج تحليل الصورة:")
        print(f"التصنيف: {result['prediction']}")
        print(f"درجة الثقة: {result['confidence']}")
        print("\nالتفاصيل:")
        for score in result['detailed_scores']:
            print(f"- {score}")
            
    except Exception as e:
        print(f"حدث خطأ: {str(e)}")
```

## Classes
The model classifies images into two categories:

- **Real Image (0)**: The image is real and not AI-generated.
- **AI Generated (1)**: The image is generated by AI.

## Technical Details
- **Model Architecture**: Vision Transformer (ViT)
- **Input**: Images (RGB)
- **Output**: Binary classification with confidence score
- **Max Image Size**: 224x224 (automatically resized)

## Requirements
- `transformers>=4.30.0`
- `torch>=2.0.0`
- `Pillow>=9.0.0`

## Limitations
- Best performance with clear, high-quality images.
- May have reduced accuracy with heavily edited photos.
- Designed for general image detection.

## Web Integration Example
```javascript
async function detectImage(imageFile) {
  const formData = new FormData();
  formData.append('image', imageFile);

  const response = await fetch('YOUR_API_ENDPOINT', {
    method: 'POST',
    body: formData
  });

  return await response.json();
}
```

## Developer
- **Created by**: yaya36095
- **License**: MIT
- **Repository**: [https://huggingface.co/yaya36095/ai-image-detector](https://huggingface.co/yaya36095/ai-image-detector)