File size: 1,260 Bytes
fa9917c
c7baec5
fa9917c
 
df18eaf
 
 
 
 
 
45d0f71
 
 
 
 
 
 
c85af71
 
 
45d0f71
2d548f2
77e17ee
 
9811602
2d548f2
 
72ea02e
dcee1e9
45d0f71
 
835a2ac
fc1fddc
45d0f71
 
 
 
 
 
 
 
fc1fddc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()