File size: 1,149 Bytes
556d2a2
ab03079
d37d256
 
556d2a2
d37d256
835f641
d37d256
 
556d2a2
ab03079
514f18c
 
 
54d632c
514f18c
 
556d2a2
 
514f18c
 
 
835f641
514f18c
ae29e32
 
 
 
 
514f18c
ae29e32
 
556d2a2
1e693c2
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
import gradio as gr
from PIL import Image
from toxic_detection import TextToxicDetector
from toxic_detection import ImgToxicDetector

text_model = TextToxicDetector()
text_model.load('szzzzz/xlm-roberta-base-text-toxic')
img_model = ImgToxicDetector()
img_model.load('./toxic_detection_res50.gz.tar')

def image_toxic_detect(im):
    return img_model.detect(Image.fromarray(im))

def text_toxic_detect(text):
    print(text)
    return text_model.detect(text)


with gr.Blocks() as app:
    gr.Markdown("Toxic Detection")
    with gr.Tab("Toxic Text Detector"):
        text_input_toxic = gr.Textbox()
        text_output_toxic = gr.Label(num_top_classes=1)
        text_button_toxic = gr.Button("text_toxic") 
    with gr.Tab("Toxic Image Detector"):
        image_input_toxic = gr.Image()
        image_output_toxic = gr.Label(num_top_classes=2)
        image_button_toxic = gr.Button("image_toxic")

    text_button_toxic.click(text_toxic_detect, inputs=text_input_toxic, outputs=text_output_toxic)
    image_button_toxic.click(image_toxic_detect, inputs=image_input_toxic, outputs=image_output_toxic)
    
    
app.launch(server_name="0.0.0.0")