yaya36095 commited on
Commit
a3994c5
·
verified ·
1 Parent(s): c839dce

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +130 -30
README.md CHANGED
@@ -1,43 +1,143 @@
1
- # AI Source Detector
2
 
3
- ## وصف النموذج
4
- هذا النموذج يعتمد على معمارية **XLM-RoBERTa** وتم تصميمه لتحديد مصدر النصوص المولدة، مثل التعرف على النصوص التي تم إنشاؤها بواسطة الذكاء الاصطناعي مقابل النصوص الحقيقية المكتوبة بواسطة البشر. يدعم النموذج مهام تصنيف النصوص متعددة اللغات.
5
 
6
- ---
 
 
 
 
7
 
8
- ## التفاصيل التقنية
 
 
 
 
9
 
10
- - **المعمارية:** XLMRobertaForSequenceClassification
11
- - **نوع النموذج:** XLM-RoBERTa
12
- - **عدد الطبقات المخفية:** 12
13
- - **عدد رؤوس الانتباه (Attention Heads):** 12
14
- - **الحجم المخفي:** 768
15
- - **نوع المشكلة:** Single Label Classification
16
- - **الإصدار المستخدم من Transformers:** 4.44.2
 
 
 
 
17
 
18
- ---
 
 
 
 
 
 
 
 
19
 
20
- ## طريقة الاستخدام
 
 
 
21
 
22
- ### Python
23
  ```python
24
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
25
  import torch
26
 
27
- # تحميل النموذج والمُرمِّز
28
- model_name = "yaya36095/ai-source-detector"
29
- tokenizer = AutoTokenizer.from_pretrained(model_name)
30
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # تحليل النص
33
- text = "This is a sample text to classify."
34
- inputs = tokenizer(text, return_tensors="pt")
35
- outputs = model(**inputs)
 
 
36
 
37
- # النتيجة
38
- logits = outputs.logits
39
- predicted_class = logits.argmax(-1).item()
 
 
40
 
41
- # التصنيفات
42
- id2label = {0: "real", 1: "ai_generated"}
43
- print(f"The text is classified as: {id2label[predicted_class]}")
 
 
1
 
2
+ AI IMAGE AND SOURCE DETECTOR
3
+ ============================
4
 
5
+ 1. AI IMAGE DETECTOR
6
+ --------------------
7
+ - Detects if an image is real or AI-generated.
8
+ - Uses Vision Transformer (ViT) architecture.
9
+ - High accuracy for various image types.
10
 
11
+ 2. AI SOURCE DETECTOR
12
+ ---------------------
13
+ - Identifies the source of AI-generated images.
14
+ - Supports: Midjourney, DALL-E, Stable Diffusion.
15
+ - Provides confidence scores.
16
 
17
+ USAGE
18
+ -----
19
+ ### Python Code Example for AI Image Detector
20
+ ```python
21
+ from transformers import ViTImageProcessor, ViTForImageClassification
22
+ from PIL import Image
23
+ import torch
24
+
25
+ # Load model and processor
26
+ processor = ViTImageProcessor.from_pretrained("yaya36095/ai-image-detector")
27
+ model = ViTForImageClassification.from_pretrained("yaya36095/ai-image-detector")
28
 
29
+ def detect_image(image_path):
30
+ image = Image.open(image_path)
31
+ inputs = processor(images=image, return_tensors="pt")
32
+ outputs = model(**inputs)
33
+ predictions = outputs.logits.softmax(dim=-1)
34
+ prediction_id = torch.argmax(predictions).item()
35
+ confidence = predictions[0][prediction_id].item() * 100
36
+ result = "AI Generated" if prediction_id == 1 else "Real Image"
37
+ return result, confidence
38
 
39
+ # Example usage
40
+ # result, confidence = detect_image("path/to/image.jpg")
41
+ # print(f"Result: {result} (Confidence: {confidence:.2f}%)")
42
+ ```
43
 
44
+ ### Python Code Example for AI Source Detector
45
  ```python
46
+ from transformers import ViTImageProcessor, ViTForImageClassification
47
+ from PIL import Image
48
  import torch
49
 
50
+ # Load model and processor
51
+ processor = ViTImageProcessor.from_pretrained("yaya36095/ai-source-detector")
52
+ model = ViTForImageClassification.from_pretrained("yaya36095/ai-source-detector")
53
+
54
+ def detect_source(image_path):
55
+ image = Image.open(image_path)
56
+ inputs = processor(images=image, return_tensors="pt")
57
+ outputs = model(**inputs)
58
+ predictions = outputs.logits.softmax(dim=-1)
59
+ prediction_id = torch.argmax(predictions).item()
60
+ confidence = predictions[0][prediction_id].item() * 100
61
+ sources = ["Real Image", "Midjourney", "DALL-E", "Stable Diffusion"]
62
+ result = sources[prediction_id]
63
+ return result, confidence
64
+
65
+ # Example usage
66
+ # result, confidence = detect_source("path/to/image.jpg")
67
+ # print(f"Source: {result} (Confidence: {confidence:.2f}%)")
68
+ ```
69
+
70
+ ### Combined Analysis Code Example
71
+ ```python
72
+ def analyze_image(image_path):
73
+ """
74
+ Analyzes an image to detect if it is AI-generated and its source.
75
+
76
+ Args:
77
+ image_path: Path to the image file
78
+
79
+ Returns:
80
+ dict: Results containing detection and source information
81
+ """
82
+ # Load models
83
+ detector = ViTForImageClassification.from_pretrained("yaya36095/ai-image-detector")
84
+ source_detector = ViTForImageClassification.from_pretrained("yaya36095/ai-source-detector")
85
+ processor = ViTImageProcessor.from_pretrained("yaya36095/ai-image-detector")
86
+
87
+ # Open and process image
88
+ image = Image.open(image_path)
89
+ inputs = processor(images=image, return_tensors="pt")
90
+
91
+ # Get AI detection result
92
+ with torch.no_grad():
93
+ outputs = detector(**inputs)
94
+ predictions = outputs.logits.softmax(dim=-1)
95
+
96
+ is_ai = torch.argmax(predictions).item() == 1
97
+ ai_confidence = predictions[0][1].item() * 100
98
+
99
+ # Get source detection if it is AI
100
+ source = "Not AI Generated"
101
+ source_confidence = 0
102
+
103
+ if is_ai:
104
+ with torch.no_grad():
105
+ outputs = source_detector(**inputs)
106
+ predictions = outputs.logits.softmax(dim=-1)
107
+
108
+ source_id = torch.argmax(predictions).item()
109
+ sources = ["Real Image", "Midjourney", "DALL-E", "Stable Diffusion"]
110
+ source = sources[source_id]
111
+ source_confidence = predictions[0][source_id].item() * 100
112
+
113
+ return {
114
+ "is_ai": is_ai,
115
+ "ai_confidence": ai_confidence,
116
+ "source": source,
117
+ "source_confidence": source_confidence
118
+ }
119
+
120
+ # Example usage:
121
+ # result = analyze_image("path/to/image.jpg")
122
+ # print(f"AI Generated: {result['is_ai']}")
123
+ # print(f"AI Confidence: {result['ai_confidence']:.2f}%")
124
+ # print(f"Source: {result['source']}")
125
+ # print(f"Source Confidence: {result['source_confidence']:.2f}%")
126
+ ```
127
 
128
+ FEATURES
129
+ --------
130
+ - Supports all image formats.
131
+ - Automatic image resizing.
132
+ - Confidence scores for predictions.
133
+ - Combined analysis (AI detection + Source).
134
 
135
+ LIMITATIONS
136
+ -----------
137
+ - Best with clear, high-quality images.
138
+ - May vary with heavily edited images.
139
+ - Requires good internet connection for first load.
140
 
141
+ For more information visit:
142
+ - [AI Image Detector](https://huggingface.co/yaya36095/ai-image-detector)
143
+ - [AI Source Detector](https://huggingface.co/yaya36095/ai-source-detector)