File size: 1,697 Bytes
8c2d9a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import prediction
import eda 

# Function to display the sentiment prediction
@st.cache_data
def get_prediction(text):
    return prediction.predict_sentiment(text)

# Main function for the Streamlit app
def main():
    st.title("Sentiment Analysis App")
    
    menu = ["Home", "Sentiment Prediction", "Exploratory Data Analysis"]
    choice = st.sidebar.selectbox("Menu", menu)

    if choice == "Home":
        st.write("""
        ## Welcome to the Sentiment Analysis App!
        Navigate to the menu on the left to:
        - Predict the sentiment of a given review text.
        - View exploratory data analysis visuals.
        """)

    elif choice == "Sentiment Prediction":
        st.write("""
        ### Sentiment Prediction
        Enter a review text below to predict its sentiment.
        """)

        # Create a text input widget
        text = st.text_area("Enter the review text:")
        if st.button("Predict"):
            sentiment = get_prediction(text)
            st.success(f"The sentiment of the review is: **{sentiment}**")

    elif choice == "Exploratory Data Analysis":
        st.write("""
        ### Exploratory Data Analysis
        View visualizations derived from the dataset.
        """)

        # Display wordcloud
        st.write("### Word Cloud for Reviews")
        st.pyplot(eda.visualize_wordcloud())  

        # Display review lengths distribution
        st.write("### Distribution of Review Lengths")
        st.pyplot(eda.plot_review_lengths())  

        # Display rating distribution
        st.write("### Rating Distribution")
        st.pyplot(eda.rating_distribution())  

if __name__ == '__main__':
    main()