Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,10 +118,19 @@ print("✅ All models loaded!")
|
|
| 118 |
# Safety Filter Function
|
| 119 |
# ----------------------
|
| 120 |
def is_caption_safe(caption):
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
unsafe_keywords = ["gun", "blood", "skull", "kill", "corpse", "gore", "knife", "weapon"]
|
| 126 |
if any(word in caption.lower() for word in unsafe_keywords):
|
| 127 |
return False
|
|
@@ -129,6 +138,7 @@ def is_caption_safe(caption):
|
|
| 129 |
|
| 130 |
|
| 131 |
|
|
|
|
| 132 |
# ----------------------
|
| 133 |
# Caption + Translate + Speak
|
| 134 |
# ----------------------
|
|
|
|
| 118 |
# Safety Filter Function
|
| 119 |
# ----------------------
|
| 120 |
def is_caption_safe(caption):
|
| 121 |
+
try:
|
| 122 |
+
votes = moderation_model(caption)
|
| 123 |
+
# If return_all_scores=True, it's [[{label, score}, ...]]
|
| 124 |
+
if isinstance(votes, list) and isinstance(votes[0], list):
|
| 125 |
+
votes = votes[0]
|
| 126 |
+
# Now safe to loop
|
| 127 |
+
for item in votes:
|
| 128 |
+
if isinstance(item, dict) and item.get("label") in ["V", "V2"] and item.get("score", 0) > 0.5:
|
| 129 |
+
return False
|
| 130 |
+
except Exception as e:
|
| 131 |
+
print("⚠️ Moderation failed:", e)
|
| 132 |
+
|
| 133 |
+
# Fallback keywords
|
| 134 |
unsafe_keywords = ["gun", "blood", "skull", "kill", "corpse", "gore", "knife", "weapon"]
|
| 135 |
if any(word in caption.lower() for word in unsafe_keywords):
|
| 136 |
return False
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
+
|
| 142 |
# ----------------------
|
| 143 |
# Caption + Translate + Speak
|
| 144 |
# ----------------------
|