├── README.md ├── main.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # textblob_sentiment_analysis 2 | A streamlit python web app to analyze sentiment in a CSV file and add the sentiment values to the file. 3 | ## Find the web app here: 4 | https://sentimentalizer.streamlit.app/ 5 | 6 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from textblob import TextBlob 2 | import pandas as pd 3 | import streamlit as st 4 | import cleantext 5 | 6 | 7 | st.header('Sentiment Analysis') 8 | with st.expander('Analyze Text'): 9 | text = st.text_input('Text here: ') 10 | if text: 11 | blob = TextBlob(text) 12 | st.write('Polarity: ', round(blob.sentiment.polarity,2)) 13 | st.write('Subjectivity: ', round(blob.sentiment.subjectivity,2)) 14 | 15 | 16 | pre = st.text_input('Clean Text: ') 17 | if pre: 18 | st.write(cleantext.clean(pre, clean_all= False, extra_spaces=True , 19 | stopwords=True ,lowercase=True ,numbers=True , punct=True)) 20 | 21 | with st.expander('Analyze CSV'): 22 | upl = st.file_uploader('Upload file') 23 | 24 | def score(x): 25 | blob1 = TextBlob(x) 26 | return blob1.sentiment.polarity 27 | 28 | # 29 | def analyze(x): 30 | if x >= 0.5: 31 | return 'Positive' 32 | elif x <= -0.5: 33 | return 'Negative' 34 | else: 35 | return 'Neutral' 36 | 37 | # 38 | if upl: 39 | df = pd.read_excel(upl) 40 | del df['Unnamed: 0'] 41 | df['score'] = df['tweets'].apply(score) 42 | df['analysis'] = df['score'].apply(analyze) 43 | st.write(df.head(10)) 44 | 45 | @st.cache 46 | def convert_df(df): 47 | # IMPORTANT: Cache the conversion to prevent computation on every rerun 48 | return df.to_csv().encode('utf-8') 49 | 50 | csv = convert_df(df) 51 | 52 | st.download_button( 53 | label="Download data as CSV", 54 | data=csv, 55 | file_name='sentiment.csv', 56 | mime='text/csv', 57 | ) 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | altair==4.2.0 2 | attrs==22.1.0 3 | beautifulsoup4==4.11.1 4 | blinker==1.5 5 | cachetools==5.2.0 6 | certifi==2022.9.24 7 | charset-normalizer==2.1.1 8 | clean-text==0.6.0 9 | click==8.1.3 10 | colorama==0.4.5 11 | commonmark==0.9.1 12 | cssselect==1.1.0 13 | decorator==5.1.1 14 | emoji==1.7.0 15 | entrypoints==0.4 16 | feedfinder2==0.0.4 17 | feedparser==6.0.10 18 | filelock==3.8.0 19 | ftfy==6.1.1 20 | gitdb==4.0.9 21 | GitPython==3.1.27 22 | idna==3.4 23 | importlib-metadata==5.0.0 24 | jieba3k==0.35.1 25 | Jinja2==3.1.2 26 | joblib==1.2.0 27 | jsonschema==4.16.0 28 | lxml==4.9.1 29 | MarkupSafe==2.1.1 30 | newspaper3k==0.2.8 31 | nltk==3.7 32 | numpy==1.23.3 33 | openpyxl==3.0.10 34 | packaging==21.3 35 | pandas==1.5.0 36 | Pillow==9.2.0 37 | protobuf==3.20.3 38 | pyarrow==9.0.0 39 | pydeck==0.8.0b3 40 | Pygments==2.13.0 41 | Pympler==1.0.1 42 | pyparsing==3.0.9 43 | pyrsistent==0.18.1 44 | python-dateutil==2.8.2 45 | pytz==2022.4 46 | pytz-deprecation-shim==0.1.0.post0 47 | PyYAML==6.0 48 | regex==2022.9.13 49 | requests==2.28.1 50 | requests-file==1.5.1 51 | rich==12.6.0 52 | semver==2.13.0 53 | sgmllib3k==1.0.0 54 | six==1.16.0 55 | smmap==5.0.0 56 | soupsieve==2.3.2.post1 57 | streamlit==1.13.0 58 | textblob==0.17.1 59 | tinysegmenter==0.3 60 | tldextract==3.3.1 61 | toml==0.10.2 62 | toolz==0.12.0 63 | tornado==6.2 64 | tqdm==4.64.1 65 | typing_extensions==4.3.0 66 | tzdata==2022.4 67 | tzlocal==4.2 68 | urllib3==1.26.12 69 | validators==0.20.0 70 | watchdog==2.1.9 71 | wcwidth==0.2.5 72 | zipp==3.8.1 73 | --------------------------------------------------------------------------------