SentimentDetector / appV0.py
Dazzler007's picture
Create appV0.py
3fc685a verified
Raw History Blame Contribute Delete
1.42 kB
import streamlit as st
from transformers import pipeline, AutoConfig
# Initialize the sentiment analysis pipeline
pipe = pipeline('sentiment-analysis')
# App Title
st.title("AI in Marketing | AI Driven | Text to Sentiment Analysis App | by Darren Field")
#st.text("Negative Sentiment - Example 1: The fish in the restaurant was not fresh.")
#st.text("Positive Sentiment - Example 2: The fish in the restaurant was fresh.")
#st.text("Positive Sentiments will reward you with ballons.")
#st.text("You get the idea ...try your own!")
st.text("To submit your text including your sentiment use (Ctrl + Enter) on your keyboard")
# Get the model name
model_name = pipe.model.name_or_path
# Get more detailed information about the model
config = AutoConfig.from_pretrained(model_name)
# Display model information
#st.write(f"Model Name: {model_name}")
#st.write(f"Model Type: {config.model_type}")
# Rest of your original code
text = st.text_area('Enter text including your sentiment.')
if text:
out = pipe(text)
st.json(out)
# Check if sentiment is positive and display balloons
if out[0]['label'] == 'POSITIVE':
st.balloons()
st.success("Positive sentiment detected! 🎉")
else:
st.info("Sentiment is not positive.")
#st.text("If you enjoyed my app, please click on the like button located at the top of")
#st.text("the page next to SentimentDector ...thank you!")