Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,22 +4,29 @@ from toxic_detection import TextToxicDetector
|
|
4 |
from toxic_detection import ImgToxicDetector
|
5 |
|
6 |
text_model = TextToxicDetector()
|
7 |
-
text_model.load('./
|
8 |
img_model = ImgToxicDetector()
|
9 |
img_model.load('./toxic_detection_res50.gz.tar')
|
10 |
|
11 |
def image_toxic_detect(im):
|
12 |
-
return
|
|
|
|
|
|
|
|
|
13 |
|
14 |
with gr.Blocks() as app:
|
15 |
-
gr.Markdown("
|
16 |
with gr.Tab("Toxic Image Detector"):
|
17 |
image_input_toxic = gr.Image()
|
18 |
image_output_toxic = gr.Label(num_top_classes=2)
|
19 |
image_button_toxic = gr.Button("image_toxic")
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
image_button_toxic.click(image_toxic_detect, inputs=image_input_toxic, outputs=image_output_toxic)
|
23 |
-
|
24 |
|
25 |
app.launch(server_name="0.0.0.0")
|
|
|
4 |
from toxic_detection import ImgToxicDetector
|
5 |
|
6 |
text_model = TextToxicDetector()
|
7 |
+
text_model.load('./text_detect_bert_16m.gz.tar')
|
8 |
img_model = ImgToxicDetector()
|
9 |
img_model.load('./toxic_detection_res50.gz.tar')
|
10 |
|
11 |
def image_toxic_detect(im):
|
12 |
+
return img_model.detect(Image.fromarray(im))
|
13 |
+
|
14 |
+
def text_toxic_detect(text):
|
15 |
+
return text_model.detect(text)
|
16 |
+
|
17 |
|
18 |
with gr.Blocks() as app:
|
19 |
+
gr.Markdown("Toxic Detection")
|
20 |
with gr.Tab("Toxic Image Detector"):
|
21 |
image_input_toxic = gr.Image()
|
22 |
image_output_toxic = gr.Label(num_top_classes=2)
|
23 |
image_button_toxic = gr.Button("image_toxic")
|
24 |
+
with gr.Tab("Toxic Text Detector"):
|
25 |
+
text_input_toxic = gr.Textbox()
|
26 |
+
text_output_toxic = gr.Label(num_top_classes=6)
|
27 |
+
text_button_toxic = gr.Button("text_toxic")
|
28 |
+
|
29 |
image_button_toxic.click(image_toxic_detect, inputs=image_input_toxic, outputs=image_output_toxic)
|
30 |
+
text_button_toxic.click(text_toxic_detect, inputs=text_input_toxic, outputs=text_output_toxic)
|
31 |
|
32 |
app.launch(server_name="0.0.0.0")
|