Spaces:
Sleeping
Sleeping
csjhonathan
commited on
Commit
·
f33f560
1
Parent(s):
b8761f5
ajusta verificação de conteúdo
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
content_model = pipeline("image-classification", model="facebook/convnext-base-224")
|
| 5 |
nsfw_model = pipeline("image-classification", model="Falconsai/nsfw_image_detection")
|
|
@@ -12,15 +13,74 @@ def analyze_image(image):
|
|
| 12 |
top_nsfw = max(nsfw_preds, key=lambda x: x["score"])
|
| 13 |
|
| 14 |
label = top_content["label"].lower()
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
adult_content = top_nsfw["label"].lower() == "nsfw"
|
| 19 |
-
violence =
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
description = f"Imagem contendo {label}. Conteúdo {'seguro' if not sensitive else 'sensível'}."
|
| 24 |
|
| 25 |
return {
|
| 26 |
"content": content_type,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
content_model = pipeline("image-classification", model="facebook/convnext-base-224")
|
| 6 |
nsfw_model = pipeline("image-classification", model="Falconsai/nsfw_image_detection")
|
|
|
|
| 13 |
top_nsfw = max(nsfw_preds, key=lambda x: x["score"])
|
| 14 |
|
| 15 |
label = top_content["label"].lower()
|
| 16 |
+
|
| 17 |
+
human_keywords = [
|
| 18 |
+
"human", "person", "people", "man", "woman", "child", "baby", "boy", "girl",
|
| 19 |
+
"face", "portrait", "selfie", "crowd", "family", "couple", "teenager"
|
| 20 |
+
]
|
| 21 |
+
is_human = any(keyword in label for keyword in human_keywords)
|
| 22 |
+
|
| 23 |
+
dog_keywords = [
|
| 24 |
+
"dog", "puppy", "retriever", "labrador", "golden", "beagle", "bulldog",
|
| 25 |
+
"poodle", "german shepherd", "chihuahua", "terrier", "hound", "mastiff",
|
| 26 |
+
"canine", "pet", "animal"
|
| 27 |
+
]
|
| 28 |
+
is_dog = any(keyword in label for keyword in dog_keywords)
|
| 29 |
+
|
| 30 |
+
violence_keywords = [
|
| 31 |
+
"blood", "wound", "injury", "hurt", "pain", "fight", "violence", "weapon",
|
| 32 |
+
"knife", "gun", "attack", "aggression", "conflict", "battle", "war"
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
suffering_keywords = [
|
| 36 |
+
"sad", "crying", "tears", "depressed", "miserable", "suffering", "pain",
|
| 37 |
+
"distress", "anguish", "grief", "mourning", "funeral", "death", "dead",
|
| 38 |
+
"dying", "illness", "sick", "injured", "abandoned", "neglected"
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
abuse_keywords = [
|
| 42 |
+
"abuse", "mistreatment", "cruelty", "torture", "beaten", "chained",
|
| 43 |
+
"caged", "starving", "malnourished", "neglected", "abandoned"
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
adult_content = top_nsfw["label"].lower() == "nsfw"
|
| 47 |
+
violence = any(keyword in label for keyword in violence_keywords)
|
| 48 |
+
suffering = any(keyword in label for keyword in suffering_keywords)
|
| 49 |
+
abuse = any(keyword in label for keyword in abuse_keywords)
|
| 50 |
+
|
| 51 |
+
sensitive = adult_content or violence or suffering or abuse
|
| 52 |
+
|
| 53 |
+
if is_human:
|
| 54 |
+
content_type = "human"
|
| 55 |
+
elif is_dog:
|
| 56 |
+
content_type = "dog"
|
| 57 |
+
else:
|
| 58 |
+
content_type = "unknown"
|
| 59 |
+
|
| 60 |
+
description_parts = []
|
| 61 |
+
|
| 62 |
+
if content_type == "human":
|
| 63 |
+
description_parts.append("Imagem contendo pessoa(s)")
|
| 64 |
+
elif content_type == "dog":
|
| 65 |
+
description_parts.append("Imagem contendo cão/cachorro")
|
| 66 |
+
else:
|
| 67 |
+
description_parts.append(f"Imagem contendo {label}")
|
| 68 |
+
|
| 69 |
+
if adult_content:
|
| 70 |
+
description_parts.append("com conteúdo adulto")
|
| 71 |
+
if violence:
|
| 72 |
+
description_parts.append("com violência")
|
| 73 |
+
if suffering:
|
| 74 |
+
description_parts.append("mostrando sofrimento")
|
| 75 |
+
if abuse:
|
| 76 |
+
description_parts.append("com maus tratos")
|
| 77 |
+
|
| 78 |
+
if sensitive:
|
| 79 |
+
description_parts.append("- CONTEÚDO SENSÍVEL")
|
| 80 |
+
else:
|
| 81 |
+
description_parts.append("- conteúdo seguro")
|
| 82 |
|
| 83 |
+
description = " ".join(description_parts) + "."
|
|
|
|
| 84 |
|
| 85 |
return {
|
| 86 |
"content": content_type,
|