🚀 Moxra - کتابخانه تشخیص محتوای نامناسب
📦 نصب
pip install moxra
یا برای استفاده از GPU:
pip install moxra[gpu]
⚡ شروع سریع
from moxra import MoxraDetector
# یک خط کد - کتابخانه آماده استفاده!
detector = MoxraDetector()
# تشخیص تصویر
result = detector.classify_with_veil("image.jpg")
print(result['is_nsfw']) # True/False
📖 راهنمای کامل
۱️⃣ ایجاد نمونه
from moxra import MoxraDetector, Config
# روش ساده
detector = MoxraDetector()
# با تنظیمات سفارشی
config = Config(device="cuda", model_type="i3")
detector = MoxraDetector(config)
# از متغیرهای محیطی
config = Config.from_env()
detector = MoxraDetector(config)
۲️⃣ تشخیص تصویر
# تشخیص با حجاب (پیشنهادی)
result = detector.classify_with_veil("photo.jpg")
# تشخیص ساده
predictions = detector.predict_image("photo.jpg")
خروجی classify_with_veil:
{
'predictions': {
'neutral': 0.85, # 85% ایمن
'sexy': 0.08, # 8% تحریککننده
'porn': 0.04, # 4% مستهجن
'hentai': 0.02, # 2% انیمه
'drawing': 0.01 # 1% نقاشی
},
'is_nsfw': False, # آیا نامناسب است؟
'is_safe': True, # آیا ایمن است؟
'is_suspicious': False, # آیا مشکوک است؟
'nsfw_score': 0.14, # امتیاز کلی
'dominant_category': 'neutral',
'veil': {
'has_veil': False, # آیا حجاب دارد؟
'confidence': 0.0 # سطح اطمینان
}
}
۳️⃣ تشخیص گیف
result = detector.predict_gif("animation.gif")
# میانگین تمام فریمها
۴️⃣ تشخیص ویدیو
result = detector.predict_video(
"video.mp4",
sample_rate=0.1, # 10% فریمها
max_frames=100 # حداکثر 100 فریم
)
خروجی ویدیو:
{
'average': {'neutral': 0.82, 'sexy': 0.07, ...},
'frames': [
{'time': 0.1, 'predictions': {...}},
{'time': 0.2, 'predictions': {...}}
],
'metadata': {
'total_frames': 300,
'processed_frames': 30,
'fps': 30,
'duration': 10.0
}
}
۵️⃣ تشخیص از داده باینری
with open("image.jpg", "rb") as f:
image_bytes = f.read()
result = detector.predict_bytes(image_bytes)
۶️⃣ تشخیص همزمان (Async)
import asyncio
async def main():
detector = MoxraDetector()
# اجرای همزمان چند تصویر
tasks = [
detector.predict_image_async("img1.jpg"),
detector.predict_image_async("img2.jpg"),
detector.predict_image_async("img3.jpg")
]
results = await asyncio.gather(*tasks)
print(results)
asyncio.run(main())
⚙️ تنظیمات پیشرفته
کلاس Config
from moxra import Config
config = Config(
model_type="i3", # d, m2, i3
device="cuda", # cpu, cuda, tensorrt
nsfw_threshold=0.85, # آستانه تشخیص
safe_threshold=0.25,
suspicious_threshold=0.60,
cleanup_interval=100, # پاکسازی حافظه
intra_threads=2, # نخهای ONNX
inter_threads=1
)
detector = MoxraDetector(config)
متغیرهای محیطی
# لینوکس/مک
export MOXRA_MODEL_TYPE="d"
export MOXRA_DEVICE="cpu"
export MOXRA_NSFW_THRESHOLD="0.85"
# ویندوز (CMD)
set MOXRA_MODEL_TYPE=d
set MOXRA_DEVICE=cpu
📊 آمار و مدیریت
# دریافت آمار
stats = detector.get_stats()
print(f"تعداد تشخیصها: {stats['inference_count']}")
print(f"دستگاه: {stats['device']}")
print(f"زمان اجرا: {stats['uptime_seconds']} ثانیه")
# پاکسازی حافظه
detector.cleanup()
🎯 دستهبندیها
| نام | توضیح | رنگ |
|---|---|---|
| neutral | محتوای ایمن و عادی | 🟢 |
| sexy | محتوای تحریککننده | 🟡 |
| porn | محتوای مستهجن | 🔴 |
| hentai | انیمه مستهجن | 🟣 |
| drawing | نقاشی و هنر | 🔵 |
💡 مثالهای کاربردی
مثال ۱: بررسی دستهای چند تصویر
from moxra import MoxraDetector
import os
detector = MoxraDetector()
images = ["img1.jpg", "img2.jpg", "img3.jpg"]
for img in images:
if os.path.exists(img):
result = detector.classify_with_veil(img)
status = "🚫 NSFW" if result['is_nsfw'] else "✅ SAFE"
print(f"{img}: {status} ({result['dominant_category']})")
مثال ۲: فیلتر خودکار تصاویر
from moxra import MoxraDetector
import shutil
detector = MoxraDetector()
def filter_images(images, safe_folder="safe", nsfw_folder="nsfw"):
for img in images:
result = detector.classify_with_veil(img)
dest = nsfw_folder if result['is_nsfw'] else safe_folder
shutil.move(img, f"{dest}/{img}")
filter_images(["photo1.jpg", "photo2.jpg", "photo3.jpg"])
مثال ۳: نمایش گرافیکی نتیجه
from moxra import MoxraDetector
detector = MoxraDetector()
result = detector.classify_with_veil("image.jpg")
print("=" * 40)
print("📊 نتیجه تشخیص")
print("=" * 40)
for cat, prob in result['predictions'].items():
bar = "█" * int(prob * 40)
print(f"{cat:10} {prob*100:5.1f}% {bar}")
print("=" * 40)
print(f"امتیاز NSFW: {result['nsfw_score']*100:.1f}%")
print(f"وضعیت: {'🚫 نامناسب' if result['is_nsfw'] else '✅ ایمن'}")
print("=" * 40)
مثال ۴: تشخیص با پیشرفت
from moxra import MoxraDetector
import time
detector = MoxraDetector()
def classify_with_progress(image_path):
print(f"⏳ در حال پردازش: {image_path}")
start = time.time()
result = detector.classify_with_veil(image_path)
elapsed = time.time() - start
print(f"✅ کامل شد در {elapsed:.2f} ثانیه")
return result
result = classify_with_progress("large_image.jpg")
🚨 خطاها
| خطا | راه حل |
|---|---|
FileNotFoundError |
مسیر فایل را بررسی کنید |
ValueError |
فرمت فایل پشتیبانی نمیشود |
RuntimeError |
خطا در پردازش، دوباره امتحان کنید |
📄 مجوز
MIT License - استفاده آزاد برای پروژههای شخصی و تجاری
👨💻 توسعهدهنده
ابوالفضل زارعی | Abolfazl Zarei
⭐ حمایت
اگر این کتابخانه برای شما مفید بود:
- ⭐ به مخزن ستاره دهید
- 📢 با دیگران به اشتراک بگذارید
- 🐛 مشکلات را گزارش کنید
ساخته شده با ❤️ برای جامعه متنباز
Release files for moxra 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| moxra-1.0.0.tar.gz | 34.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moxra-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.1 kB
Release files / moxra-1.0.0.tar.gz
| Download URL | moxra-1.0.0.tar.gz |
|---|---|
| Size | 34.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19149548ea1a115d1c6ee8204a3f1af9ad73a062d8bd9f00e8271996f594e11f
|
|
BLAKE2b-256 checksum How to use checksums |
f25946a5e82c93690552023a0a529e415775ef0d3c5fba4c2043101af688b4ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / moxra-1.0.0-py3-none-any.whl
| Download URL | moxra-1.0.0-py3-none-any.whl |
|---|---|
| Size | 33.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33ccdd0562a375507d6e88e57f37f31d4fc2ae7a9cc01c13c614b92f3b2de296
|
|
BLAKE2b-256 checksum How to use checksums |
5a192d9045fad3e61e2de6ef492fd4458a259aa7885ef1fbf3aecd1aac29109b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|