# 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}")