File size: 1,923 Bytes
13ed2c5
 
 
 
 
 
 
e1a6a08
e782a88
00eb125
e1a6a08
 
 
 
 
 
 
 
 
 
 
 
 
13ed2c5
 
 
 
 
 
b5ca399
e1a6a08
13ed2c5
b5ca399
 
 
 
 
 
 
 
 
 
 
 
ef2611a
b5ca399
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
38
39
40
41
42
43
44
45
46
47
import streamlit as st 
from transformers import pipeline, AutoConfig

# Initialize the sentiment analysis pipeline
pipe = pipeline('sentiment-analysis')

# App Title
st.title("Text to Sentiment")
#st.text("Enter your text and click the 'Analyze Sentiment' button to submit.")

# Display final score and quiz progress
st.sidebar.write("About")
st.sidebar.write(f"Sentiment Detector is a text to Sentiment Analysis app by Darren Field.")
st.sidebar.write(f"Examples:")
st.sidebar.write(f"The fish in the restaurant was not fresh")
st.sidebar.write(f"The fish in the restaurant was very fresh")
st.sidebar.write(f"The product's design feels cheap and lacks durability")
st.sidebar.write(f"The product's design feels expensive and durable")
st.sidebar.write(f"Customer service has been unresponsive, making it difficult to resolve issues.")
st.sidebar.write(f"Customer service has been fast, making it easy to resolve issues.")
st.sidebar.write(f"This simple app leverages AI to detect positive and negative sentiment in text. The text is scored and classified as either Positive or Negative sentiment.")
st.sidebar.write(f"The concept can be extended or modifed to solve many requirements.")

# 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. Postitive sentiments will be rewared with balloons')

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