SineTheta commited on
Commit
cf160e1
1 Parent(s): 608fc4f

Create new file

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import re
3
+
4
+ from transformers import pipeline
5
+
6
+ sp_model = "SineTheta/Spam_and_bully_detection"
7
+ ca_model = "SineTheta/Spam_and_bully_detection"
8
+ sp_analysis = pipeline("text-classification", model=sp_model, tokenizer=sp_model)
9
+ ca_analysis = pipeline("text-classification", model=ca_model, tokenizer=ca_model)
10
+
11
+ def bullying_analysis(language, text):
12
+ if language == 'English':
13
+ results = sp_analysis(text)
14
+ elif language == 'French':
15
+ results = ca_analysis(text)
16
+ return results[0]["label"], round(results[0]["score"], 5)
17
+
18
+
19
+ gradio_ui = gr.Interface(
20
+ fn=bullying_analysis,
21
+ title="CyberBullying Detector (Spanish/Catalan)",
22
+ description="Enter some text and check if the model detects bullying.",
23
+ inputs=[
24
+ gr.inputs.Radio(['Spanish','Catalan'],label='Language',),
25
+ gr.inputs.Textbox(lines=5, label="Paste some text here"),
26
+ ],
27
+ outputs=[
28
+ gr.outputs.Textbox(label="Label"),
29
+ gr.outputs.Textbox(label="Score"),
30
+ ],
31
+ examples=[
32
+ ['Spanish', "Eres mas alto que un pino y mas tonto que un pepino!"],
33
+ ['Catalan', "Ets un barrufet!"],
34
+ ['Spanish', "Estas mas gordo que una foca!"],
35
+ ['Catalan', "Ets mes lleig que un pecat!"],
36
+ ],
37
+ )
38
+
39
+ gradio_ui.launch()