gilramos's picture
Update app.py
448041d verified
raw
history blame
1.63 kB
import gradio as gr
import torch
from transformers import pipeline
app_title = "Portuguese Hate Speech Detection"
app_description = """
This app detects hate speech on Portuguese text using multiple models. You can either introduce your own sentences by filling in "Text" or click on one of the examples provided below.
"""
app_examples = [
["As pessoas tem que perceber que ser 'panasca' não é deixar de ser homem, é deixar de ser humano hahaha"],
["Hoje tive uma conversa muito agradável com um colega meu"],
]
output_textbox_component_description = """
This box will display the hate speech detection results based on the average score of multiple models.
"""
output_json_component_description = { "breakdown": """
This box presents a detailed breakdown of the evaluation for each model.
"""}
model_list = [
"knowhate/HateBERTimbau",
"knowhate/HateBERTimbau-youtube",
"knowhate/HateBERTimbau-twitter",
"knowhate/HateBERTimbau-yt-tt",
]
#pipe = pipeline("text-classification", model="knowhate/HateBERTimbau")
#demo = gr.Interface.from_pipeline(pipe)
#demo.launch()
def predict(chosen_model):
# Initialize the pipeline with the chosen model
predicted_label = pipeline("text-classification", model=chosen_model)
return predicted_label
inputs = [
gr.Textbox(label="Text", value=app_examples[0][0]),
gr.Dropdown(label="Model", choices=model_list, value=model_list[0])
]
outputs = [
gr.Label(label="Result"),
]
gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title=app_title,
description=app_description,
examples=app_examples).launch()