Spaces:
Runtime error
Runtime error
File size: 1,197 Bytes
0e46a6f 7a4b44a d5ab659 0e46a6f ee41f8a 0e46a6f ee41f8a 7a4b44a f94b58f 0e46a6f 4e4d22d f154ee6 0e46a6f ee41f8a 824c411 f94b58f 7a4b44a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import streamlit as st
from transformers import pipeline
if "sentiment" not in st.session_state:
st.session_state.sentiment = ""
if "score" not in st.session_state:
st.session_state.score = ""
def run_model(text_in, model_in):
classifier = pipeline(task="sentiment-analysis",
model=model_in)
analysis = classifier(text_in)
st.session_state.sentiment = analysis[0]["label"]
st.session_state.score = "{:.2f}".format(analysis[0]["score"] * 100)
models_available = {"Roberta Large English": "siebert/sentiment-roberta-large-english",
"Generic": "Seethal/sentiment_analysis_generic_dataset",
"Twitter Roberta": "cardiffnlp/twitter-roberta-base-sentiment"}
st.title("Sentiment Analysis Web Application")
text_input = st.text_area(
label="Enter the text to analyze", value="I Love Pizza")
model_picked = st.selectbox(
"Choose a model to run on", options=models_available.keys())
st.button("Submit", on_click=run_model, args=(
text_input, models_available[model_picked]))
st.markdown(body="Sentiment: {}, Confidence Score: {} %".format(
st.session_state.sentiment, st.session_state.score))
|