Spaces:
Runtime error
Runtime error
Added no profanity handle
Browse files
app.py
CHANGED
@@ -72,7 +72,6 @@ def fuzzy_lookup(tweet):
|
|
72 |
for prof_variant in prof_varations:
|
73 |
tweet = tweet.replace(prof_variant, profanity)
|
74 |
|
75 |
-
print('Fuzzy Returns:', tweet)
|
76 |
return tweet, matches
|
77 |
|
78 |
|
@@ -131,24 +130,30 @@ def query(payload):
|
|
131 |
def predict(tweet):
|
132 |
|
133 |
fuzzy_text, matches = fuzzy_lookup(tweet)
|
134 |
-
|
135 |
-
|
|
|
|
|
136 |
if 'error' in output:
|
137 |
-
return output['error'], 'Error occured. Try again later.', {
|
|
|
|
|
138 |
else:
|
139 |
output = [tuple(i.values()) for i in output[0]]
|
140 |
output = dict((x, y) for x, y in output)
|
141 |
predicted_label = list(output.keys())[0]
|
142 |
|
143 |
if predicted_label == 'Abusive':
|
|
|
144 |
for base_word, _ in matches.items():
|
145 |
-
|
146 |
tweet = tweet.replace(base_word, re.sub("[a-zA-Z0-9@]", "*", base_word))
|
147 |
-
|
148 |
return output, tweet, json.dumps(matches)
|
149 |
else:
|
150 |
return output, tweet, json.dumps(matches)
|
151 |
|
|
|
|
|
|
|
152 |
hf_writer = gr.HuggingFaceDatasetSaver('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', 'tagalog-profanity-feedbacks')
|
153 |
|
154 |
|
|
|
72 |
for prof_variant in prof_varations:
|
73 |
tweet = tweet.replace(prof_variant, profanity)
|
74 |
|
|
|
75 |
return tweet, matches
|
76 |
|
77 |
|
|
|
130 |
def predict(tweet):
|
131 |
|
132 |
fuzzy_text, matches = fuzzy_lookup(tweet)
|
133 |
+
processed_text = preprocess(fuzzy_text)
|
134 |
+
output = query(processed_text)
|
135 |
+
match_profanities = set(processed_text.split()) & set(list(profanities.keys()))
|
136 |
+
|
137 |
if 'error' in output:
|
138 |
+
return output['error'], 'Error occured. Try again later.', {}
|
139 |
+
elif len(match_profanities) == 0:
|
140 |
+
return 'No Profanity Found.', '', {}
|
141 |
else:
|
142 |
output = [tuple(i.values()) for i in output[0]]
|
143 |
output = dict((x, y) for x, y in output)
|
144 |
predicted_label = list(output.keys())[0]
|
145 |
|
146 |
if predicted_label == 'Abusive':
|
147 |
+
# Censor
|
148 |
for base_word, _ in matches.items():
|
|
|
149 |
tweet = tweet.replace(base_word, re.sub("[a-zA-Z0-9@]", "*", base_word))
|
|
|
150 |
return output, tweet, json.dumps(matches)
|
151 |
else:
|
152 |
return output, tweet, json.dumps(matches)
|
153 |
|
154 |
+
# output, tweet, matches = predict('Sama ng ugali mo pre')
|
155 |
+
# print(output, '\n', tweet, '\n', matches)
|
156 |
+
|
157 |
hf_writer = gr.HuggingFaceDatasetSaver('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', 'tagalog-profanity-feedbacks')
|
158 |
|
159 |
|