Spaces:
Sleeping

File size: 3,578 Bytes
90c4bff
 
ea736e9
 
 
 
6c08e5d
501620e
9e6bc35
ea736e9
e4c2b5e
0fe5d64
f515b3b
9a6575f
d82763d
ea736e9
86bf400
841382b
6def42c
 
 
5f8b2a8
6e66938
86bf400
f9f465b
 
4854b5e
c222fda
e4c2b5e
 
 
 
 
 
 
 
 
 
 
 
4b69008
14cc385
c222fda
 
e4c2b5e
 
 
 
 
 
 
 
e5a88ed
6bd345e
e4c2b5e
6bd345e
e4c2b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28e0794
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import nltk
nltk.download('stopwords')
from textblob import TextBlob
import pandas as pd
import streamlit as st
import cleantext


st.title("Sentiment Analysis")

#st.header('Sentiment Analysis')
st.sidebar.image("sent.png")
st.sidebar.title("Main Menu")
app_mode = st.sidebar.selectbox("Options",
["About", "Analyze Text", "Analyze CSV"])

if app_mode == "About":
    st.subheader("Project Description")
    st.markdown("The sentiment analysis project aims to develop a machine learning model that can accurately classify and analyze the sentiment expressed in textual data. ")
    st.markdown("By utilizing natural language processing techniques, the project will focus on training a model to understand and interpret emotions, opinions, and attitudes conveyed in the text. The model will be trained on a diverse dataset consisting of comment reviews, social media posts, and other textual data sources. ")
    st.markdown("This project is aimed at providing valuable insights into sentiment trends, enabling people to better understand feedback, improve decision-making processes, and enhance overall user experiences.")
    st.image("sentiment.jpeg")

elif app_mode == "Analyze Text":
    st.subheader("Analyze Text")
    st.markdown("Enter a sentence which is to be analyzed.")
    st.markdown("The Polarity and the Subjectivity of the sentence will be calculated to determine if the sentence carries weight or not.")
    with st.expander('Analyze Text'):
            text = st.text_input('Text here: ')
            if text:
                blob = TextBlob(text)
                st.write('Polarity: ', round(blob.sentiment.polarity,2))
                st.write('Subjectivity: ', round(blob.sentiment.subjectivity,2))
        
        
            pre = st.text_input('Clean Text: ')
            if pre:
                cleaned_text=cleantext.clean(pre, extra_spaces=True ,
                                         stopwords=True ,lowercase=True ,numbers=True , punct=True)
                st.write(cleaned_text)

    
else:
     with st.expander('Analyze CSV'):
            upl = st.file_uploader('Upload file')
        
            def score(x):
                blob1 = TextBlob(x)
                return blob1.sentiment.polarity
        
        #
            def analyze(x):
                print("Polarity: ", x)
                if x > 0.5:
                    return 'Positive'
                elif x < -0.5:
                    return 'Negative'
                else:
                    return 'Neutral'
        
        #
            if upl:
                df = pd.read_excel(upl)
                if 'Unnamed: 0' in df.columns:
                    df.drop('Unnamed: 0', axis=1, inplace=True)
                    #del df['Unnamed: 0']
               # if 'tweets'in df.columns:
                df['score'] = df['tweets'].apply(score)
                df['analysis'] = df['score'].apply(analyze)
                st.write(df.head(10))
        
                #@st.cache
                @st.cache_data
                def convert_df(df):
                        # IMPORTANT: Cache the conversion to prevent computation on every rerun
                    return df.to_csv().encode('utf-8')
        
                csv = convert_df(df)
        
                st.download_button(
                    label="Download data as CSV",
                    data=csv,
                    file_name='sentiment.csv',
                    mime='text/csv',
                    )
        #else:
             #st.write('Error: The uploaded file does not contain a "tweets" column.')