Spaces:
Build error
Build error
# -*- coding: utf-8 -*- | |
"""app.py | |
Automatically generated by Colab. | |
Original file is located at | |
https://colab.research.google.com/drive/1mHMq54a9glSyzg_CVIP0wshX9T8NUtmx | |
""" | |
import gradio as gr | |
from transformers import pipeline | |
pipe = pipeline(model="delarosajav95/HateSpeech-BETO-cased-v2") | |
#function that Gradio will use to classify | |
def classify_text(inputs): | |
result = pipe(inputs, return_all_scores=True) | |
output = [] | |
label_mapping = { | |
'LABEL_0': 'Non-Hate Speech', | |
'LABEL_1': 'Hate Speech' | |
} | |
for i, predictions in enumerate(result): | |
for pred in predictions: | |
label = label_mapping.get(pred['label'], pred['label']) | |
score = pred['score'] | |
output.append(f"{label}: {score:.2%}") | |
return "\n".join(output) | |
#defining Gradio interface | |
textbox = gr.Textbox(lines=3, placeholder="Type a Spanish statement, comment, or review for evaluation (e.g., 'Esas personas no merecen respeto.')", | |
label="User Comment/Post:") | |
output_box = gr.Textbox(label="Results:") | |
iface = gr.Interface( | |
fn=classify_text, | |
inputs=textbox, | |
outputs=output_box, | |
live=True, | |
title="Spanish Hate Speech Classifier for User Content", | |
allow_flagging="never", | |
) | |
# Launch the interface | |
iface.launch() |