Spaces:
Runtime error
Runtime error
Commit
β’
00621f5
0
Parent(s):
Duplicate from danielferreira/emotion-text-classification
Browse filesCo-authored-by: Daniel Ferreira <[email protected]>
- .gitattributes +27 -0
- README.md +38 -0
- app.py +53 -0
- requirements.txt +74 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Emotion Text Classification
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
app_file: app.py
|
8 |
+
pinned: false
|
9 |
+
duplicated_from: danielferreira/emotion-text-classification
|
10 |
+
---
|
11 |
+
|
12 |
+
# Configuration
|
13 |
+
|
14 |
+
`title`: _string_
|
15 |
+
Display title for the Space
|
16 |
+
|
17 |
+
`emoji`: _string_
|
18 |
+
Space emoji (emoji-only character allowed)
|
19 |
+
|
20 |
+
`colorFrom`: _string_
|
21 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
22 |
+
|
23 |
+
`colorTo`: _string_
|
24 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
25 |
+
|
26 |
+
`sdk`: _string_
|
27 |
+
Can be either `gradio` or `streamlit`
|
28 |
+
|
29 |
+
`sdk_version` : _string_
|
30 |
+
Only applicable for `streamlit` SDK.
|
31 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
32 |
+
|
33 |
+
`app_file`: _string_
|
34 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
35 |
+
Path is relative to the root of the repository.
|
36 |
+
|
37 |
+
`pinned`: _boolean_
|
38 |
+
Whether the Space stays on top of your list.
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
3 |
+
|
4 |
+
|
5 |
+
class EmotionClassifier:
|
6 |
+
def __init__(self, model_name: str):
|
7 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
self.pipeline = pipeline(
|
10 |
+
"text-classification",
|
11 |
+
model=self.model,
|
12 |
+
tokenizer=self.tokenizer,
|
13 |
+
return_all_scores=True,
|
14 |
+
)
|
15 |
+
|
16 |
+
def predict(self, input_text: str):
|
17 |
+
pred = self.pipeline(input_text)[0]
|
18 |
+
result = {
|
19 |
+
"Sadness π": pred[0]["score"],
|
20 |
+
"Joy π": pred[1]["score"],
|
21 |
+
"Love π": pred[2]["score"],
|
22 |
+
"Anger π ": pred[3]["score"],
|
23 |
+
"Fear π¨": pred[4]["score"],
|
24 |
+
"Surprise π²": pred[5]["score"],
|
25 |
+
}
|
26 |
+
return result
|
27 |
+
|
28 |
+
|
29 |
+
def main():
|
30 |
+
model = EmotionClassifier("bhadresh-savani/bert-base-uncased-emotion")
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=model.predict,
|
33 |
+
inputs=gr.inputs.Textbox(
|
34 |
+
lines=3,
|
35 |
+
placeholder="Type a phrase that has some emotion",
|
36 |
+
label="Input Text",
|
37 |
+
),
|
38 |
+
outputs="label",
|
39 |
+
title="Emotion Classification",
|
40 |
+
examples=[
|
41 |
+
"I get so down when I'm alone",
|
42 |
+
"I believe that today everything will work out",
|
43 |
+
"It was so dark there I was afraid to go",
|
44 |
+
"I loved the gift you gave me",
|
45 |
+
"I was very surprised by your presentation.",
|
46 |
+
],
|
47 |
+
)
|
48 |
+
|
49 |
+
iface.launch()
|
50 |
+
|
51 |
+
|
52 |
+
if __name__ == "__main__":
|
53 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
analytics-python==1.4.0
|
2 |
+
backcall==0.2.0
|
3 |
+
backoff==1.10.0
|
4 |
+
bcrypt==3.2.0
|
5 |
+
certifi==2021.10.8
|
6 |
+
cffi==1.15.0
|
7 |
+
charset-normalizer==2.0.8
|
8 |
+
click==8.0.3
|
9 |
+
cryptography==36.0.0
|
10 |
+
cycler==0.11.0
|
11 |
+
debugpy==1.5.1
|
12 |
+
decorator==5.1.0
|
13 |
+
entrypoints==0.3
|
14 |
+
ffmpy==0.3.0
|
15 |
+
filelock==3.4.0
|
16 |
+
Flask==2.0.2
|
17 |
+
Flask-CacheBuster==1.0.0
|
18 |
+
Flask-Cors==3.0.10
|
19 |
+
Flask-Login==0.5.0
|
20 |
+
fonttools==4.28.2
|
21 |
+
gradio==2.4.6
|
22 |
+
huggingface-hub==0.1.2
|
23 |
+
idna==3.3
|
24 |
+
ipykernel==6.5.1
|
25 |
+
ipython==7.30.0
|
26 |
+
itsdangerous==2.0.1
|
27 |
+
jedi==0.18.1
|
28 |
+
Jinja2==3.0.3
|
29 |
+
joblib==1.1.0
|
30 |
+
jupyter-client==7.1.0
|
31 |
+
jupyter-core==4.9.1
|
32 |
+
kiwisolver==1.3.2
|
33 |
+
markdown2==2.4.1
|
34 |
+
MarkupSafe==2.0.1
|
35 |
+
matplotlib==3.5.0
|
36 |
+
matplotlib-inline==0.1.3
|
37 |
+
monotonic==1.6
|
38 |
+
nest-asyncio==1.5.1
|
39 |
+
numpy==1.21.4
|
40 |
+
packaging==21.3
|
41 |
+
pandas==1.3.4
|
42 |
+
paramiko==2.8.1
|
43 |
+
parso==0.8.2
|
44 |
+
pexpect==4.8.0
|
45 |
+
pickleshare==0.7.5
|
46 |
+
Pillow==8.4.0
|
47 |
+
prompt-toolkit==3.0.23
|
48 |
+
ptyprocess==0.7.0
|
49 |
+
pycparser==2.21
|
50 |
+
pycryptodome==3.11.0
|
51 |
+
pydub==0.25.1
|
52 |
+
Pygments==2.10.0
|
53 |
+
PyNaCl==1.4.0
|
54 |
+
pyparsing==3.0.6
|
55 |
+
python-dateutil==2.8.2
|
56 |
+
pytz==2021.3
|
57 |
+
PyYAML==6.0
|
58 |
+
pyzmq==22.3.0
|
59 |
+
regex==2021.11.10
|
60 |
+
requests==2.26.0
|
61 |
+
sacremoses==0.0.46
|
62 |
+
setuptools-scm==6.3.2
|
63 |
+
six==1.16.0
|
64 |
+
tokenizers==0.10.3
|
65 |
+
tomli==1.2.2
|
66 |
+
torch==1.10.0
|
67 |
+
tornado==6.1
|
68 |
+
tqdm==4.62.3
|
69 |
+
traitlets==5.1.1
|
70 |
+
transformers==4.12.5
|
71 |
+
typing-extensions==4.0.0
|
72 |
+
urllib3==1.26.7
|
73 |
+
wcwidth==0.2.5
|
74 |
+
Werkzeug==2.0.2
|