Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -124,7 +124,7 @@ print(f"- Moderadores: {len(moderators)}")
|
|
| 124 |
print(f"{'='*60}\n")
|
| 125 |
|
| 126 |
# Limiar AUMENTADO para evitar falsos positivos
|
| 127 |
-
TOXICITY_THRESHOLD = 0.
|
| 128 |
|
| 129 |
# Mapeamento expandido de labels
|
| 130 |
LABEL_MAPPING = {
|
|
@@ -151,6 +151,7 @@ LABEL_MAPPING = {
|
|
| 151 |
def verificar_linguagem(texto):
|
| 152 |
"""
|
| 153 |
Verifica linguagem imprópria com MAIS modelos e threshold MAIOR
|
|
|
|
| 154 |
"""
|
| 155 |
if not moderators or len(texto.strip()) < 3:
|
| 156 |
return False, 0.0
|
|
@@ -163,14 +164,25 @@ def verificar_linguagem(texto):
|
|
| 163 |
label = resultado['label'].lower()
|
| 164 |
score = resultado['score']
|
| 165 |
|
| 166 |
-
# Interpretar com
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
toxicity = score
|
| 171 |
-
|
| 172 |
-
#
|
| 173 |
toxicity = 1 - score
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
scores_toxicos.append(toxicity)
|
| 176 |
|
|
@@ -286,6 +298,12 @@ def analisar_texto(texto):
|
|
| 286 |
# VERIFICAR LINGUAGEM (com threshold mais alto)
|
| 287 |
has_improper, improper_score = verificar_linguagem(texto)
|
| 288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
# Formatar resultado
|
| 290 |
if has_improper:
|
| 291 |
resultado_texto = f"""**{classificacao}**
|
|
@@ -395,7 +413,11 @@ with gr.Blocks(title="Análise de Sentimentos Avançada") as demo:
|
|
| 395 |
|
| 396 |
**Moderadores Ativos:** {len(moderators)} / {len(MODERATION_MODELS)}
|
| 397 |
|
| 398 |
-
**Threshold:** {TOXICITY_THRESHOLD*100:.0f}% (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
**Modelos:**
|
| 401 |
- DistilBERT Toxicity
|
|
|
|
| 124 |
print(f"{'='*60}\n")
|
| 125 |
|
| 126 |
# Limiar AUMENTADO para evitar falsos positivos
|
| 127 |
+
TOXICITY_THRESHOLD = 0.80 # Aumentado para reduzir falsos positivos
|
| 128 |
|
| 129 |
# Mapeamento expandido de labels
|
| 130 |
LABEL_MAPPING = {
|
|
|
|
| 151 |
def verificar_linguagem(texto):
|
| 152 |
"""
|
| 153 |
Verifica linguagem imprópria com MAIS modelos e threshold MAIOR
|
| 154 |
+
Com interpretação melhorada de labels
|
| 155 |
"""
|
| 156 |
if not moderators or len(texto.strip()) < 3:
|
| 157 |
return False, 0.0
|
|
|
|
| 164 |
label = resultado['label'].lower()
|
| 165 |
score = resultado['score']
|
| 166 |
|
| 167 |
+
# Interpretar labels com MAIS cuidado
|
| 168 |
+
# Labels que indicam TOXICIDADE
|
| 169 |
+
toxic_keywords = ['toxic', 'hate', 'offensive', 'hateful', 'obscene', 'threat', 'insult']
|
| 170 |
+
# Labels que indicam NORMALIDADE
|
| 171 |
+
normal_keywords = ['not', 'normal', 'neutral', 'clean']
|
| 172 |
|
| 173 |
+
is_toxic_label = any(word in label for word in toxic_keywords)
|
| 174 |
+
is_normal_label = any(word in label for word in normal_keywords)
|
| 175 |
+
|
| 176 |
+
# Calcular toxicity score com lógica melhorada
|
| 177 |
+
if is_toxic_label and not is_normal_label:
|
| 178 |
+
# Label diz que é tóxico
|
| 179 |
toxicity = score
|
| 180 |
+
elif is_normal_label or 'not' in label:
|
| 181 |
+
# Label diz que NÃO é tóxico
|
| 182 |
toxicity = 1 - score
|
| 183 |
+
else:
|
| 184 |
+
# Label ambíguo, assumir score direto se alto
|
| 185 |
+
toxicity = score if score > 0.5 else 1 - score
|
| 186 |
|
| 187 |
scores_toxicos.append(toxicity)
|
| 188 |
|
|
|
|
| 298 |
# VERIFICAR LINGUAGEM (com threshold mais alto)
|
| 299 |
has_improper, improper_score = verificar_linguagem(texto)
|
| 300 |
|
| 301 |
+
# LÓGICA INTELIGENTE: Se Positivo com boa confiança, provavelmente não é ofensivo
|
| 302 |
+
if classificacao == 'Positivo' and confianca_final > 0.70:
|
| 303 |
+
has_improper = False # Ignora alerta para textos claramente positivos
|
| 304 |
+
|
| 305 |
+
# Se Neutro ou Negativo, ainda verifica normalmente
|
| 306 |
+
|
| 307 |
# Formatar resultado
|
| 308 |
if has_improper:
|
| 309 |
resultado_texto = f"""**{classificacao}**
|
|
|
|
| 413 |
|
| 414 |
**Moderadores Ativos:** {len(moderators)} / {len(MODERATION_MODELS)}
|
| 415 |
|
| 416 |
+
**Threshold:** {TOXICITY_THRESHOLD*100:.0f}% (mais alto para evitar falsos positivos)
|
| 417 |
+
|
| 418 |
+
**Lógica Inteligente:**
|
| 419 |
+
- Textos claramente positivos (>70% confiança) não geram alertas
|
| 420 |
+
- Foco em detectar problemas reais
|
| 421 |
|
| 422 |
**Modelos:**
|
| 423 |
- DistilBERT Toxicity
|