Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,6 +78,7 @@ moderation_model = pipeline(
|
|
| 78 |
model="Vrandan/Comment-Moderation",
|
| 79 |
return_all_scores=True
|
| 80 |
)
|
|
|
|
| 81 |
from PIL import Image
|
| 82 |
import torch
|
| 83 |
from gtts import gTTS
|
|
@@ -117,20 +118,17 @@ print("β
All models loaded!")
|
|
| 117 |
# Safety Filter Function
|
| 118 |
# ----------------------
|
| 119 |
def is_caption_safe(caption):
|
| 120 |
-
# Run the moderation model to get scores
|
| 121 |
votes = moderation_model(caption)[0]
|
| 122 |
-
# Check for violence/graphic violence labels
|
| 123 |
for item in votes:
|
| 124 |
-
if item["label"] in ["V", "V2"] and item["score"] > 0.5:
|
| 125 |
return False
|
| 126 |
-
|
| 127 |
-
unsafe_keywords = [
|
| 128 |
-
"gun", "blood", "skull", "kill", "corpse", "gore", "knife", "weapon"
|
| 129 |
-
]
|
| 130 |
if any(word in caption.lower() for word in unsafe_keywords):
|
| 131 |
return False
|
| 132 |
return True
|
| 133 |
|
|
|
|
|
|
|
| 134 |
# ----------------------
|
| 135 |
# Caption + Translate + Speak
|
| 136 |
# ----------------------
|
|
|
|
| 78 |
model="Vrandan/Comment-Moderation",
|
| 79 |
return_all_scores=True
|
| 80 |
)
|
| 81 |
+
|
| 82 |
from PIL import Image
|
| 83 |
import torch
|
| 84 |
from gtts import gTTS
|
|
|
|
| 118 |
# Safety Filter Function
|
| 119 |
# ----------------------
|
| 120 |
def is_caption_safe(caption):
|
|
|
|
| 121 |
votes = moderation_model(caption)[0]
|
|
|
|
| 122 |
for item in votes:
|
| 123 |
+
if item["label"] in ["V", "V2"] and item["score"] > 0.5: # Violence / Graphic Violence
|
| 124 |
return False
|
| 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
|
| 128 |
return True
|
| 129 |
|
| 130 |
+
|
| 131 |
+
|
| 132 |
# ----------------------
|
| 133 |
# Caption + Translate + Speak
|
| 134 |
# ----------------------
|