JonatanGk commited on
Commit
dc95fd2
1 Parent(s): c14e9e2

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +3 -29
  2. app.py +39 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,37 +1,11 @@
1
  ---
2
- title: Cyberbullying Detector
3
- emoji: 🏃
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
  app_file: app.py
8
- pinned: false
9
  ---
10
 
11
- # Configuration
12
 
13
- `title`: _string_
14
- Display title for the Space
15
-
16
- `emoji`: _string_
17
- Space emoji (emoji-only character allowed)
18
-
19
- `colorFrom`: _string_
20
- Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
21
-
22
- `colorTo`: _string_
23
- Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
24
-
25
- `sdk`: _string_
26
- Can be either `gradio` or `streamlit`
27
-
28
- `sdk_version` : _string_
29
- Only applicable for `streamlit` SDK.
30
- See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
31
-
32
- `app_file`: _string_
33
- Path to your main application file (which contains either `gradio` or `streamlit` Python code).
34
- Path is relative to the root of the repository.
35
-
36
- `pinned`: _boolean_
37
- Whether the Space stays on top of your list.
1
  ---
2
+ title: CyberBullying Detector
3
+ emoji: 😭
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
  app_file: app.py
8
+ pinned: true
9
  ---
10
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "JonatanGk/roberta-base-bne-finetuned-cyberbullying-spanish"
7
+ ca_model = "JonatanGk/roberta-base-ca-finetuned-cyberbullying-catalan"
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 == 'Spanish':
13
+ results = sp_analysis(text)
14
+ elif language == 'Catalan':
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 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()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ transformers
2
+ torch