Spaces:
Runtime error
Runtime error
App updated
Browse files- README.md +4 -4
- app.py +28 -2
- tweet_pipeline.py +37 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: streamlit
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Tweet Evaluator
|
| 3 |
+
emoji: π¦
|
| 4 |
+
colorFrom: DeepSkyBlue
|
| 5 |
+
colorTo: LightSkyBlue
|
| 6 |
sdk: streamlit
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
app.py
CHANGED
|
@@ -1,4 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
from tweet_pipeline import TweetPipeline
|
| 4 |
+
|
| 5 |
+
EMOTION_EMOJIS = {"Anger": "π‘", "Joy": "π", "Optimism": "π", "Sadness": "π’"}
|
| 6 |
+
OFFENSIVE_EMOJIS = {"Offensive": "π", "Non-Offensive": "π"}
|
| 7 |
+
SENTIMENT_EMOJIS = {"Negative": "β", "Neutral": "π€·ββοΈ", "Positive": "β
"}
|
| 8 |
+
|
| 9 |
+
tweet_eval = TweetPipeline()
|
| 10 |
+
|
| 11 |
+
st.title("π¦ Tweet Evaluator")
|
| 12 |
+
input_text = st.text_input("")
|
| 13 |
+
|
| 14 |
+
button = st.button("Evaluate!")
|
| 15 |
+
|
| 16 |
+
if button and input_text != "":
|
| 17 |
+
with st.spinner("Evaluating tweet..."):
|
| 18 |
+
prediction = tweet_eval(input_text)
|
| 19 |
+
st.success("Tweet successfully evaluated!")
|
| 20 |
+
st.markdown(
|
| 21 |
+
f"{EMOTION_EMOJIS[prediction['emotion']]} **Emotion:** {prediction['emotion']}"
|
| 22 |
+
)
|
| 23 |
+
st.markdown(
|
| 24 |
+
f"{OFFENSIVE_EMOJIS[prediction['offensive']]} **Offensive:** {'Yes' if prediction['offensive'] == 'Offensive' else 'No'}"
|
| 25 |
+
)
|
| 26 |
+
st.markdown(
|
| 27 |
+
f"{SENTIMENT_EMOJIS[prediction['sentiment']]} **Sentiment:** {prediction['sentiment']}"
|
| 28 |
+
)
|
| 29 |
+
elif button and not input_text:
|
| 30 |
+
st.warning("Please, introduce a tweet to eval.")
|
tweet_pipeline.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import Dict
|
| 3 |
+
|
| 4 |
+
from transformers import (
|
| 5 |
+
AutoModelForSequenceClassification,
|
| 6 |
+
AutoTokenizer,
|
| 7 |
+
TextClassificationPipeline,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class TweetPipeline:
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.emotion_pipeline = TextClassificationPipeline(
|
| 14 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
| 15 |
+
"elozano/tweet_emotion_eval"
|
| 16 |
+
),
|
| 17 |
+
tokenizer=AutoTokenizer.from_pretrained("elozano/tweet_emotion_eval"),
|
| 18 |
+
)
|
| 19 |
+
self.offensive_pipeline = TextClassificationPipeline(
|
| 20 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
| 21 |
+
"elozano/tweet_offensive_eval"
|
| 22 |
+
),
|
| 23 |
+
tokenizer=AutoTokenizer.from_pretrained("elozano/tweet_offensive_eval"),
|
| 24 |
+
)
|
| 25 |
+
self.sentiment_pipeline = TextClassificationPipeline(
|
| 26 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
| 27 |
+
"elozano/tweet_sentiment_eval"
|
| 28 |
+
),
|
| 29 |
+
tokenizer=AutoTokenizer.from_pretrained("elozano/tweet_sentiment_eval"),
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
def __call__(self, text: str) -> Dict[str, str]:
|
| 33 |
+
return {
|
| 34 |
+
"emotion": self.emotion_pipeline(text)[0]["label"],
|
| 35 |
+
"offensive": self.offensive_pipeline(text)[0]["label"],
|
| 36 |
+
"sentiment": self.sentiment_pipeline(text)[0]["label"],
|
| 37 |
+
}
|