Spaces:
No application file
No application file
Commit ·
0465686
1
Parent(s): 56e18b5
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859from textblob import TextBlobimport pandas as pdimport streamlit as stimport cleantext
st.header('Sentiment Analysis')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: st.write(cleantext.clean(pre, clean_all= False, extra_spaces=True , stopwords=True ,lowercase=True ,numbers=True , punct=True))
with st.expander('Analyze CSV'): upl = st.file_uploader('Upload file')
def score(x): blob1 = TextBlob(x) return blob1.sentiment.polarity
# def analyze(x): if x >= 0.5: return 'Positive' elif x <= -0.5: return 'Negative' else: return 'Neutral'
# if upl: df = pd.read_excel(upl) del df['Unnamed: 0'] df['score'] = df['tweets'].apply(score) df['analysis'] = df['score'].apply(analyze) st.write(df.head(10))
@st.cache 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', )
app.pyAdded+59