File size: 1,020 Bytes
e43d57f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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("Enter your text and click the 'Analyze Sentiment' button to submit.")

# Get the model name
model_name = pipe.model.name_or_path

# Get more detailed information about the model
config = AutoConfig.from_pretrained(model_name)

# Text input area
text = st.text_area('Enter text including your sentiment.')

# Submit button
if st.button('Analyze 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.")
    else:
        st.warning("Please enter some text before analyzing.")