اكتشاف صور NSFW
يقوم Discuse بتقييم الصور التي يرسلها المستخدمون لاكتشاف المحتوى الصريح بهدف الإشراف عليها. أرسل عناوين URL للصور إلى POST https://api.discuse.com/api/v2/check مع تفعيل check_images، وستُرجع API احتمالات porn وsexual وneutral بالإضافة إلى علامة hit ضمن كائن results.images.
كيف يعمل اكتشاف NSFW؟
يعيد نموذج الرؤية الحاسوبية في Discuse ثلاثة احتمالات لكل صورة، يكون مجموعها قريبًا من 1.0:
porn: احتمال أن تكون الصورة إباحية.sexual: احتمال أن تكون الصورة ذات إيحاء جنسي.neutral: احتمال أن تكون الصورة آمنة.
تشير علامة hit إلى أن الصورة تجاوزت حدود NSFW المحددة لمشروعك. استخدم الدرجات الخام للتمييز بين صورة صريحة بوضوح (حظر تلقائي) وصورة على الحدّ الفاصل (مراجعة بشرية).
كيف أفحص صورة؟
أرسل عنوان URL واحدًا أو أكثر للصور وفعّل فحص الصور باستخدام check_images:
curl -X POST https://api.discuse.com/api/v2/check \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"content": {
"image_urls": ["https://example.com/user-upload.jpg"]
},
"settings": {
"check_images": true
}
}'
يقبل الطلب الواحد ما يصل إلى 10 عناوين URL للصور.
تنسيق الاستجابة
{
"has_violations": true,
"cached": false,
"message": "NSFW content detected",
"results": {
"hits": true,
"images": {
"status": "ok",
"porn": 0.95,
"sexual": 0.85,
"neutral": 0.02,
"hit": true
}
},
"usage": {
"api_requests_used": 12,
"api_requests_limit": 2000,
"api_requests_remaining": 1988
}
}
توجد نتيجة الصورة ضمن results.images. يظهر processing_time_ms فقط عند تفعيل قياس الوقت في إعدادات مشروعك.
فحص عدة صور
{
"content": {
"image_urls": [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg"
]
},
"settings": {
"check_images": true
}
}
تُحتسب كل صورة يتم فحصها بشكل منفصل من حصة فحص الصور لديك.
كيف أفسّر الدرجات؟
porn وsexual وneutral هي احتمالات من 0.0 إلى 1.0. في الصورة الصريحة، تكون قيمة porn مرتفعة وneutral منخفضة؛ أما في الصورة الآمنة فتكون neutral هي الغالبة.
function interpretImageResult(result) {
const img = result.results.images;
if (img.porn > 0.8) {
return 'block'; // automatically reject
} else if (img.porn > 0.5 || img.sexual > 0.7) {
return 'review'; // queue for human review
} else if (img.sexual > 0.5) {
return 'warn'; // allow with a content-warning label
} else {
return 'allow';
}
}
يمكنك أيضًا الاعتماد على علامة hit، فهي تطبّق بالفعل إعدادات threshold_images_porn وthreshold_images_sexual الخاصة بمشروعك.
حالات الاستخدام
المنصات الاجتماعية
افحص صور الملفات الشخصية وصور المنشورات قبل نشرها:
async function handleImageUpload(imageUrl) {
const result = await checkImage(imageUrl);
const img = result.results.images;
if (img.porn > 0.7) {
throw new Error('This image violates our community guidelines');
}
if (img.sexual > 0.7) {
return { url: imageUrl, hasContentWarning: true };
}
return { url: imageUrl, hasContentWarning: false };
}
المتاجر الإلكترونية
طبّق حدًا أكثر صرامة على صور المنتجات:
def validate_product_image(image_url):
result = check_image(image_url)
img = result['results']['images']
if img['porn'] > 0.3 or img['sexual'] > 0.3:
return {'approved': False, 'reason': 'Image contains inappropriate content'}
return {'approved': True}
أفضل الممارسات
افحص قبل التخزين الدائم
async function processUpload(file) {
const tempUrl = await uploadToTemp(file);
const result = await checkImage(tempUrl);
if (result.has_violations) {
await deleteTempFile(tempUrl);
throw new Error('Image rejected');
}
return await moveToPermanent(tempUrl);
}
ادمج ذلك مع الإشراف على النصوص
يمكن لطلب واحد فحص صورة وتعليقها النصي معًا:
{
"content": {
"text": "Check out this photo from my vacation!",
"image_urls": ["https://example.com/vacation.jpg"]
},
"settings": {
"check_sentiment": true,
"check_spam": true,
"check_images": true
}
}
استخدم النتائج المخزنة مؤقتًا
لا تُحتسب الاستجابات المخزنة مؤقتًا من حصتك، لذلك فإن إعادة عرض صورة سبق فحصها أو التحقق منها مجددًا تكون مجانية. تخبرك علامة cached في الاستجابة متى جاءت النتيجة من الذاكرة المؤقتة.
حدود الاستخدام
| الخطة | فحوصات الصور الشهرية | تكلفة التجاوز |
|---|---|---|
| Basic | 500 | غير متاح |
| Gold | 2,000 | $0.00075/scan |
| Platinum | 5,000 | $0.00064/scan (خصم 15%) |
| Ultimate | 10,000 | $0.00056/scan (خصم 25%) |
أمثلة التكامل
Node.js
const checkImage = async (imageUrl) => {
const response = await fetch('https://api.discuse.com/api/v2/check', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.DISCUSE_API_KEY
},
body: JSON.stringify({
content: { image_urls: [imageUrl] },
settings: { check_images: true }
})
});
return response.json();
};
Python
import os
import requests
def check_image(image_url):
response = requests.post(
'https://api.discuse.com/api/v2/check',
headers={
'Content-Type': 'application/json',
'X-API-Key': os.environ['DISCUSE_API_KEY']
},
json={
'content': {'image_urls': [image_url]},
'settings': {'check_images': True}
}
)
return response.json()
الخطوات التالية
- تحليل النصوص - أضف تقييم المشاعر والرسائل المزعجة إلى الطلب نفسه
- اكتشاف اللغة - اكتشف لغة المحتوى وطبّقها
- فحص الملفات بمضاد الفيروسات - افحص المستندات بحثًا عن البرمجيات الخبيثة