File size: 1,038 Bytes
e0d35f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37

# Libraries

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

# Milestone 2

# title
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.")

# use a select box for pretrained models
option = st.selectbox(
    "Select a pretrained model for sentiment analysis",
    ("siebert/sentiment-roberta-large-english", "yiyanghkust/finbert-tone", "finiteautomata/bertweet-base-sentiment-analysis"))

# display selection
st.write("You selected:", option)

# run pipeline
sentiment_pipeline = pipeline("sentiment-analysis", model = option)

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