Initial commit
Browse files- README.md +2 -28
- app.py +39 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,37 +1,11 @@
|
|
1 |
---
|
2 |
title: Catalonia Independence Detector
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: pink
|
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: Catalonia Independence Detector
|
3 |
+
emoji: 👎👍
|
4 |
+
colorFrom: yellow
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
7 |
app_file: app.py
|
8 |
pinned: false
|
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-catalonia-independence-detector"
|
7 |
+
ca_model = "JonatanGk/roberta-base-ca-finetuned-catalonia-independence-detector"
|
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="Catalonia independence detector (Spanish/Catalan)",
|
22 |
+
description="Enter some text and check if model detects is favor/neutral/against Catalonia independence.",
|
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', "Junqueras, sobre la decisión judicial sobre Puigdemont: La justicia que falta en el Estado llega y llegará de Europa"],
|
33 |
+
['Spanish', "Desconvocada la manifestación del domingo en Barcelona en apoyo a Puigdemont"],
|
34 |
+
['Catalan', "Puigdemont, a l'estat espanyol: Quatre anys després, ens hem guanyat el dret a dir prou"],
|
35 |
+
['Catalan', "Llarena demana la detenció de Comín i Ponsatí aprofitant que són a Itàlia amb Puigdemont"],
|
36 |
+
],
|
37 |
+
)
|
38 |
+
|
39 |
+
gradio_ui.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|