gilramos's picture
Update app.py
72ea02e verified
raw
history blame
1.26 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.
"""
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(text, chosen_model):
# Initialize the pipeline with the chosen model
model_pipeline = pipeline("text-classification", model=chosen_model)
result = model_pipeline(text)
label = result[0]['label']
return label
inputs = [
gr.Textbox(label="Text", value= "As pessoas tem que perceber que ser 'panasca' não é deixar de ser homem, é deixar de ser humano kkk"),
gr.Dropdown(label="Model", choices=model_list, value=model_list[1])
]
outputs = [
gr.Label(label="Result"),
]
gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title=app_title,
description=app_description).launch()