File size: 815 Bytes
58eb48c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# Libraries

import streamlit as st
import tensorflow as tf
from transformers import pipeline

# Milestone 2

# select a pretrained model
sentiment_pipeline = pipeline("sentiment-analysis", model = "siebert/sentiment-roberta-large-english")

# intro
st.title("Sentiment Analysis App")
st.write("Enter some text and I'll predict its sentiment!")

# add a text input box
text_input = st.text_input("Enter your text here:", value = "The weather is nice today.")

# run the model when the user clicks submit
if st.button("Submit"):
    
    # get result
    sentiment = sentiment_pipeline(text_input)
    
    # split into sentiment and score
    sen = sentiment[0]['label']
    score = round(sentiment[0]['score'], 4)
    
    # display the prediction
    st.write(f"Sentiment: {sen}   ,   Confidence Score: {score}")