Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from huggingface_hub import from_pretrained_keras
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
app_title = "Portuguese Counter Hate Speech Detection"
|
|
@@ -19,10 +20,12 @@ For more, visit our [website](https://knowhate.eu) and [Hugging Face page](https
|
|
| 19 |
"""
|
| 20 |
|
| 21 |
def_model = 'knowhate/counterhate-youtube-bertimbau'
|
|
|
|
| 22 |
|
| 23 |
model_list = [
|
| 24 |
def_model,
|
| 25 |
"knowhate/counterhate-twitter-xlmrobertabase",
|
|
|
|
| 26 |
"knowhate/counterhate-twitter-bertbasemultilingualcased",
|
| 27 |
"knowhate/counterhate-twitter-bertimbau"
|
| 28 |
]
|
|
@@ -30,6 +33,7 @@ model_list = [
|
|
| 30 |
kw_to_hf = {"knowhate/counterhate-twitter-bertimbau": "neuralmind/bert-base-portuguese-cased",
|
| 31 |
"knowhate/counterhate-youtube-bertimbau": "neuralmind/bert-base-portuguese-cased",
|
| 32 |
"knowhate/counterhate-twitter-xlmrobertabase": "xlm-roberta-base",
|
|
|
|
| 33 |
"knowhate/counterhate-twitter-bertbasemultilingualcased": "bert-base-multilingual-cased",
|
| 34 |
"knowhate/counterhate-youtube-hateberttuga": "knowhate/hateberttuga",
|
| 35 |
"knowhate/counterhate-twitter-hateberttuga": "knowhate/hateberttuga"}
|
|
@@ -44,9 +48,52 @@ app_examples = [
|
|
| 44 |
def_model],
|
| 45 |
["Então o Marcelo foi ao Qatar para 'falar de direitos humanos', mas não foi a Odemira?",
|
| 46 |
"esse retardado mental, foi a praia do katar, la tem a agua mais kentinha.",
|
| 47 |
-
def_model]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
]
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def predict(text, target, chosen_model):
|
| 51 |
# model1 = tf.keras.models.load_model(chosen_model, custom_objects={"TFBertModel": TFBertModel})
|
| 52 |
model1 = from_pretrained_keras(chosen_model)
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from huggingface_hub import from_pretrained_keras
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
|
| 10 |
app_title = "Portuguese Counter Hate Speech Detection"
|
|
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
def_model = 'knowhate/counterhate-youtube-bertimbau'
|
| 23 |
+
def_model2 = 'knowhate/counterhate-twitter-xlmrobertabase-cleantxt'
|
| 24 |
|
| 25 |
model_list = [
|
| 26 |
def_model,
|
| 27 |
"knowhate/counterhate-twitter-xlmrobertabase",
|
| 28 |
+
def_model2,
|
| 29 |
"knowhate/counterhate-twitter-bertbasemultilingualcased",
|
| 30 |
"knowhate/counterhate-twitter-bertimbau"
|
| 31 |
]
|
|
|
|
| 33 |
kw_to_hf = {"knowhate/counterhate-twitter-bertimbau": "neuralmind/bert-base-portuguese-cased",
|
| 34 |
"knowhate/counterhate-youtube-bertimbau": "neuralmind/bert-base-portuguese-cased",
|
| 35 |
"knowhate/counterhate-twitter-xlmrobertabase": "xlm-roberta-base",
|
| 36 |
+
"knowhate/counterhate-twitter-xlmrobertabase-cleantxt": "xlm-roberta-base",
|
| 37 |
"knowhate/counterhate-twitter-bertbasemultilingualcased": "bert-base-multilingual-cased",
|
| 38 |
"knowhate/counterhate-youtube-hateberttuga": "knowhate/hateberttuga",
|
| 39 |
"knowhate/counterhate-twitter-hateberttuga": "knowhate/hateberttuga"}
|
|
|
|
| 48 |
def_model],
|
| 49 |
["Então o Marcelo foi ao Qatar para 'falar de direitos humanos', mas não foi a Odemira?",
|
| 50 |
"esse retardado mental, foi a praia do katar, la tem a agua mais kentinha.",
|
| 51 |
+
def_model],
|
| 52 |
+
["Essa gente tem é de deixar de ser apaparicada pelo Estado e começar a cumprir os seus deveres como cidadãos.",
|
| 53 |
+
"Nepia o que faz com que as pessoas generalizem é o ódio intrínseco que têm contra uma etnia, ng é responsável pela sua xenofobia",
|
| 54 |
+
def_model2],
|
| 55 |
+
["\"Não acredites em tudo o que lês na Internet\" - Abraham Lincoln",
|
| 56 |
+
"A Internet foi desenvolvida entre os anos 1973-1989.",
|
| 57 |
+
def_model2],
|
| 58 |
+
["Então o Marcelo foi ao Qatar para 'falar de direitos humanos', mas não foi a Odemira?",
|
| 59 |
+
"esse retardado mental, foi a praia do katar, la tem a agua mais kentinha.",
|
| 60 |
+
def_model2]
|
| 61 |
+
|
| 62 |
]
|
| 63 |
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def remove_emojis(data):
|
| 67 |
+
if '@' in data:
|
| 68 |
+
data = re.sub(r"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z0-9-_]+[A-Za-z0-9-_]+)", "", data).strip()
|
| 69 |
+
|
| 70 |
+
if 'https' in data:
|
| 71 |
+
data = re.sub(
|
| 72 |
+
r"(?i)\b(?:[a-z][\w.+-]+:(?:/{1,3}|[?+]?[a-z0-9%]))(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\x60!()\[\]{};:'\".,<>?«»“”‘’])",
|
| 73 |
+
"", data).strip()
|
| 74 |
+
|
| 75 |
+
emoj = re.compile("["
|
| 76 |
+
u"\U0001F600-\U0001F64F" # emoticons
|
| 77 |
+
u"\U0001F300-\U0001F5FF" # symbols & pictographs
|
| 78 |
+
u"\U0001F680-\U0001F6FF" # transport & map symbols
|
| 79 |
+
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
|
| 80 |
+
u"\U00002500-\U00002BEF" # chinese char
|
| 81 |
+
u"\U00002702-\U000027B0"
|
| 82 |
+
u"\U000024C2-\U0001F251"
|
| 83 |
+
u"\U0001f926-\U0001f937"
|
| 84 |
+
u"\U00010000-\U0010ffff"
|
| 85 |
+
u"\u2640-\u2642"
|
| 86 |
+
u"\u2600-\u2B55"
|
| 87 |
+
u"\u200d"
|
| 88 |
+
u"\u23cf"
|
| 89 |
+
u"\u23e9"
|
| 90 |
+
u"\u231a"
|
| 91 |
+
u"\ufe0f" # dingbats
|
| 92 |
+
u"\u3030"
|
| 93 |
+
"]+", re.UNICODE)
|
| 94 |
+
return re.sub(emoj, '', data)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
def predict(text, target, chosen_model):
|
| 98 |
# model1 = tf.keras.models.load_model(chosen_model, custom_objects={"TFBertModel": TFBertModel})
|
| 99 |
model1 = from_pretrained_keras(chosen_model)
|