Spaces:
Running
Running
Kingston Yip
commited on
Commit
·
60d7ec1
1
Parent(s):
3a09ea8
updates
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from pysentimiento import create_analyzer
|
|
|
4 |
|
5 |
-
hate_speech_analyzer = create_analyzer(task="hate_speech", lang="es")
|
6 |
|
7 |
-
pipe = pipeline(task="sentiment-analysis")
|
8 |
st.title("Toxic Tweets Analyzer")
|
9 |
image = "kanye_tweet.jpg"
|
10 |
st.image(image, use_column_width=True)
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
#form
|
16 |
with st.form("my_form"):
|
17 |
submitted = st.form_submit_button("Analyze")
|
18 |
tweet = st.text_area("enter tweet here:", value="i'm nice at ping pong")
|
19 |
if submitted:
|
20 |
-
out =
|
21 |
-
if model == "sentiment-analysis transformer":
|
22 |
-
out = pipe(tweet)
|
23 |
-
else:
|
24 |
-
out = hate_speech_analyzer.predict(tweet)
|
25 |
|
|
|
|
|
|
|
|
|
26 |
st.json(out)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from pysentimiento import create_analyzer
|
4 |
+
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
|
5 |
|
|
|
6 |
|
|
|
7 |
st.title("Toxic Tweets Analyzer")
|
8 |
image = "kanye_tweet.jpg"
|
9 |
st.image(image, use_column_width=True)
|
10 |
|
11 |
+
|
12 |
+
#select model
|
13 |
+
model_name = st.selectbox("Select model", ["distilbert-base-uncased-finetuned-sst-2-english", "finiteautomata/bertweet-base-sentiment-analysis"])
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
15 |
+
model = TFAutoModelForSequenceClassification.from_pretrained(model_name)
|
16 |
+
clf = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
17 |
|
18 |
#form
|
19 |
with st.form("my_form"):
|
20 |
submitted = st.form_submit_button("Analyze")
|
21 |
tweet = st.text_area("enter tweet here:", value="i'm nice at ping pong")
|
22 |
if submitted:
|
23 |
+
out = clf(tweet)
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
#loading bar
|
26 |
+
st.spinner(text="...")
|
27 |
+
st.success('Done!')
|
28 |
+
st.balloons()
|
29 |
st.json(out)
|