Spaces:
Runtime error
Runtime error
MJ
commited on
Commit
·
7a4b44a
1
Parent(s):
c912008
Added States to automatically update markdown
Browse files
app.py
CHANGED
@@ -1,20 +1,19 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
def run_model(text_in, model_in):
|
9 |
classifier = pipeline(task="sentiment-analysis",
|
10 |
model=model_in)
|
11 |
analysis = classifier(text_in)
|
12 |
-
|
13 |
-
|
14 |
-
to_output += "Sentiment: ", output["label"], " Confidence Score: ", "{0:.2f}".format(
|
15 |
-
output["score"] * 100), "\n"
|
16 |
-
global markdown_text
|
17 |
-
markdown_text = to_output
|
18 |
|
19 |
|
20 |
models_available = {"Roberta Large English": "siebert/sentiment-roberta-large-english",
|
@@ -30,5 +29,5 @@ model_picked = st.selectbox(
|
|
30 |
st.button("Submit", on_click=run_model, args=(
|
31 |
text_input, models_available[model_picked]))
|
32 |
|
33 |
-
|
34 |
-
st.
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
if "sentiment" not in st.session_state:
|
5 |
+
st.session_state.sentiment = ""
|
6 |
+
|
7 |
+
if "score" not in st.session_state:
|
8 |
+
st.session_state.score = ""
|
9 |
|
10 |
|
11 |
def run_model(text_in, model_in):
|
12 |
classifier = pipeline(task="sentiment-analysis",
|
13 |
model=model_in)
|
14 |
analysis = classifier(text_in)
|
15 |
+
st.session_state.sentiment = analysis[0]["label"]
|
16 |
+
st.session_state.score = "{0:2f}".format(analysis[0]["score"] * 100)
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
models_available = {"Roberta Large English": "siebert/sentiment-roberta-large-english",
|
|
|
29 |
st.button("Submit", on_click=run_model, args=(
|
30 |
text_input, models_available[model_picked]))
|
31 |
|
32 |
+
st.markdown(body="Sentiment: {}, Score, {}".format(
|
33 |
+
st.session_state.sentiment, st.session_state.score))
|