Spaces:
Runtime error
Runtime error
Commit
·
6f4cbae
1
Parent(s):
c8ace9c
Update app.py
Browse filesAdded final code
app.py
CHANGED
|
@@ -1,20 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import twarc
|
| 4 |
-
import twarc_csv
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import numpy as np
|
| 7 |
-
from requests_oauthlib import OAuth1Session
|
| 8 |
-
import json
|
| 9 |
-
from datetime import datetime, timezone, timedelta
|
| 10 |
-
from twarc.client2 import Twarc2
|
| 11 |
-
from twarc_csv import DataFrameConverter #CSVConverter
|
| 12 |
-
from textblob import TextBlob
|
| 13 |
-
|
| 14 |
-
# Create header to display information about the data
|
| 15 |
-
#st.header("This app runs a sentiment analysis on the replies to a tweet. To begin, \
|
| 16 |
-
# copy the URL from the tweet you want to analyze, and paste it below.")
|
| 17 |
-
|
| 18 |
st.header("This app runs a sentiment analysis on the replies to a Tweet from Facebook when they announced their rebranding to Meta on October 28th, 2021")
|
| 19 |
|
| 20 |
st.subheader("The Tweet analyzed for this project can be viewed here: ")
|
|
@@ -22,5 +6,39 @@ st.subheader("The Tweet analyzed for this project can be viewed here: ")
|
|
| 22 |
st.markdown("")
|
| 23 |
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HEADER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
st.header("This app runs a sentiment analysis on the replies to a Tweet from Facebook when they announced their rebranding to Meta on October 28th, 2021")
|
| 3 |
|
| 4 |
st.subheader("The Tweet analyzed for this project can be viewed here: ")
|
|
|
|
| 6 |
st.markdown("")
|
| 7 |
|
| 8 |
|
| 9 |
+
# LIBRARY IMPORTS
|
| 10 |
+
import streamlit as st
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import sys
|
| 13 |
+
from streamlit import cli as stcli
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# DATA IMPORT
|
| 17 |
+
# Import data from "df_redacted.csv" as a dataframe
|
| 18 |
+
df_redacted = pd.read_csv('df_redacted.csv')
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# DISPLAY RESULTS
|
| 22 |
+
# Create dictionary of sentiment categories and corresponding scores
|
| 23 |
+
values = df_redacted['sentiment_score'].value_counts(dropna=False).keys().tolist()
|
| 24 |
+
counts = df_redacted['sentiment_score'].value_counts(dropna=False).tolist()
|
| 25 |
+
value_dict = dict(zip(values, counts))
|
| 26 |
+
|
| 27 |
+
# Calculate the max of all 3 sentiment categories
|
| 28 |
+
sentiment = max(value_dict, key=value_dict.get)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
# Display the count for each sentiment category and overall sentiment of the tweet replies
|
| 33 |
+
st.write('Highest sentiment category for the replies to the Facebook Tweet announcing Meta: ', sentiment)
|
| 34 |
+
st.write(value_dict)
|
| 35 |
+
# Display histogram of count for each sentiment category
|
| 36 |
+
st.bar_chart(df_redacted['sentiment_score'].value_counts())
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
if st._is_running_with_streamlit:
|
| 41 |
+
main()
|
| 42 |
+
else:
|
| 43 |
+
sys.argv = ["streamlit", "run", sys.argv[0]]
|
| 44 |
+
sys.exit(stcli.main())
|