Spaces:
Runtime error
Runtime error
Emotion detection space.
Browse files- .streamlit/config.toml +3 -0
- README.md +3 -4
- app.py +20 -0
- requirements.txt +2 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
base="light"
|
3 |
+
primaryColor="#d756ff"
|
README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
---
|
2 |
title: Emotion Detection
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.17.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Emotion Detection
|
3 |
+
emoji: π
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: purple
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.17.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
@st.cache_resource(show_spinner="Loading model...")
|
5 |
+
def load_pipe():
|
6 |
+
pipe = pipeline(task="text-classification", model="cnicu/tweet_emotions_classifier")
|
7 |
+
return pipe
|
8 |
+
|
9 |
+
def classify_emotion(text: str, pipe: pipeline) -> str:
|
10 |
+
prediction = pipe(text)
|
11 |
+
return prediction
|
12 |
+
|
13 |
+
st.title("Tweet emotions classification")
|
14 |
+
|
15 |
+
text = st.text_area("Tweet to classify", label_visibility='hidden')
|
16 |
+
|
17 |
+
if st.button("Classify tweet", disabled= text == ''):
|
18 |
+
with st.spinner("In progress..."):
|
19 |
+
prediction = classify_emotion(text, load_pipe())
|
20 |
+
st.success(f"Tweet's emotion: **{prediction[0]['label']}**")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|