Spaces:
Runtime error
Runtime error
File size: 1,104 Bytes
e941ca1 17bed6e e941ca1 17bed6e e941ca1 17bed6e e941ca1 |
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 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
import streamlit as st
@st.cache
def sentiment_analysis(inp):
model_name = 'distilbert-base-uncased-finetuned-sst-2-english'
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
res = classifier(inp)
return res
def main():
st.header("Check the sentiment of your text")
my_string = 'Hello, it was fun making this streamlit application.'
user_input = st.text_input("Enter text here:", value=my_string)
st.write("You entered:", user_input)
res = sentiment_analysis(user_input)
print(res)
with st.form("my_form"):
submit_button = st.form_submit_button(label='Submit')
sentiment = res[0]['label']
conf = res[0]['score']
if submit_button:
st.write("Sentiment of the input: ", sentiment)
st.write("Confidence of the predicted sentiment: ", conf)
if __name__ == '__main__':
main() |