Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,15 @@ from nudenet import NudeDetector
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
|
| 7 |
-
# تشغيل كاشف الأجزاء الحساسة
|
| 8 |
detector = NudeDetector()
|
| 9 |
|
| 10 |
-
#
|
| 11 |
UNSAFE_PARTS = [
|
| 12 |
"FEMALE_BREAST_EXPOSED",
|
| 13 |
-
"FEMALE_BREAST_COVERED", # ملابس السباحة والبيكيني
|
| 14 |
"BUTTOCKS_EXPOSED",
|
| 15 |
"BUTTOCKS_COVERED",
|
| 16 |
"FEMALE_GENITALIA_EXPOSED",
|
|
@@ -18,15 +19,15 @@ UNSAFE_PARTS = [
|
|
| 18 |
"BELLY_EXPOSED"
|
| 19 |
]
|
| 20 |
|
|
|
|
| 21 |
def censor_target_only(image):
|
| 22 |
if image is None:
|
| 23 |
return None, {"status": "لا توجد صورة"}
|
| 24 |
|
| 25 |
-
# تحويل الصورة لمعالجتها
|
| 26 |
img_np = np.array(image.convert("RGB"))
|
| 27 |
img_cv = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
|
| 28 |
|
| 29 |
-
# كشف
|
| 30 |
detections = detector.detect(img_np)
|
| 31 |
|
| 32 |
censored_count = 0
|
|
@@ -35,10 +36,9 @@ def censor_target_only(image):
|
|
| 35 |
for item in detections:
|
| 36 |
part_name = item['class']
|
| 37 |
score = item['score']
|
| 38 |
-
box = item['box']
|
| 39 |
|
| 40 |
-
|
| 41 |
-
if part_name in UNSAFE_PARTS and score >= 0.40:
|
| 42 |
censored_count += 1
|
| 43 |
details.append(f"{part_name} ({round(score * 100)}%)")
|
| 44 |
|
|
@@ -47,10 +47,9 @@ def censor_target_only(image):
|
|
| 47 |
x2 = min(img_cv.shape[1], x + w)
|
| 48 |
y2 = min(img_cv.shape[0], y + h)
|
| 49 |
|
| 50 |
-
#
|
| 51 |
target_area = img_cv[y:y2, x:x2]
|
| 52 |
if target_area.size > 0:
|
| 53 |
-
# تغبيش قوي جداً للمنطقة المحددة
|
| 54 |
blurred = cv2.GaussianBlur(target_area, (65, 65), 35)
|
| 55 |
img_cv[y:y2, x:x2] = blurred
|
| 56 |
|
|
@@ -60,7 +59,7 @@ def censor_target_only(image):
|
|
| 60 |
return result_image, {
|
| 61 |
"censored_parts": censored_count,
|
| 62 |
"details": details,
|
| 63 |
-
"status": f"🚨 تم حجب {censored_count} موضع فقط" if censored_count > 0 else "✅
|
| 64 |
}
|
| 65 |
|
| 66 |
demo = gr.Interface(
|
|
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
+
import spaces
|
| 7 |
|
| 8 |
+
# تشغيل كاشف الأجزاء الحساسة
|
| 9 |
detector = NudeDetector()
|
| 10 |
|
| 11 |
+
# الأجزاء الممنوعة
|
| 12 |
UNSAFE_PARTS = [
|
| 13 |
"FEMALE_BREAST_EXPOSED",
|
| 14 |
+
"FEMALE_BREAST_COVERED", # ملابس السباحة والبيكيني
|
| 15 |
"BUTTOCKS_EXPOSED",
|
| 16 |
"BUTTOCKS_COVERED",
|
| 17 |
"FEMALE_GENITALIA_EXPOSED",
|
|
|
|
| 19 |
"BELLY_EXPOSED"
|
| 20 |
]
|
| 21 |
|
| 22 |
+
@spaces.GPU
|
| 23 |
def censor_target_only(image):
|
| 24 |
if image is None:
|
| 25 |
return None, {"status": "لا توجد صورة"}
|
| 26 |
|
|
|
|
| 27 |
img_np = np.array(image.convert("RGB"))
|
| 28 |
img_cv = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
|
| 29 |
|
| 30 |
+
# كشف مواضع العري
|
| 31 |
detections = detector.detect(img_np)
|
| 32 |
|
| 33 |
censored_count = 0
|
|
|
|
| 36 |
for item in detections:
|
| 37 |
part_name = item['class']
|
| 38 |
score = item['score']
|
| 39 |
+
box = item['box']
|
| 40 |
|
| 41 |
+
if part_name in UNSAFE_PARTS and score >= 0.35:
|
|
|
|
| 42 |
censored_count += 1
|
| 43 |
details.append(f"{part_name} ({round(score * 100)}%)")
|
| 44 |
|
|
|
|
| 47 |
x2 = min(img_cv.shape[1], x + w)
|
| 48 |
y2 = min(img_cv.shape[0], y + h)
|
| 49 |
|
| 50 |
+
# حجب هذا الجزء فقط
|
| 51 |
target_area = img_cv[y:y2, x:x2]
|
| 52 |
if target_area.size > 0:
|
|
|
|
| 53 |
blurred = cv2.GaussianBlur(target_area, (65, 65), 35)
|
| 54 |
img_cv[y:y2, x:x2] = blurred
|
| 55 |
|
|
|
|
| 59 |
return result_image, {
|
| 60 |
"censored_parts": censored_count,
|
| 61 |
"details": details,
|
| 62 |
+
"status": f"🚨 تم حجب {censored_count} موضع فقط" if censored_count > 0 else "✅ آمنة"
|
| 63 |
}
|
| 64 |
|
| 65 |
demo = gr.Interface(
|