nickmuchi commited on
Commit
978b2e2
β€’
1 Parent(s): 89553ed

Update 01_🏠_Home.py

Browse files
Files changed (1) hide show
  1. 01_🏠_Home.py +8 -33
01_🏠_Home.py CHANGED
@@ -10,6 +10,8 @@ import plotly_express as px
10
  import plotly.graph_objects as go
11
  from datetime import datetime as dt
12
  from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
 
 
13
 
14
  st.set_page_config(
15
  page_title="Live FinTwitter Analysis",
@@ -20,42 +22,15 @@ st.set_page_config(
20
  st.sidebar.header("Sentiment Analysis Score")
21
 
22
  extract_time = dt.strftime(dt.today(),"%d_%B_%y_%H_%M")
23
-
24
- @st.experimental_singleton(suppress_st_warning=True)
25
- def load_models():
26
- '''load sentimant and topic clssification models'''
27
- sent_pipe = pipeline(task,model=sent_model_id, tokenizer=sent_model_id)
28
- topic_pipe = pipeline(task, model=topic_model_id, tokenizer=topic_model_id)
29
-
30
- return sent_pipe, topic_pipe
31
-
32
- @st.cache(allow_output_mutation=True, suppress_st_warning=True)
33
- def process_tweets(df,df_users):
34
- '''process tweets into a dataframe'''
35
-
36
- df['author'] = df['author'].astype(np.int64)
37
-
38
- df_merged = df.merge(df_users, on='author')
39
-
40
- tweet_list = df_merged['tweet'].tolist()
41
-
42
- sentiment, topic = pd.DataFrame(sentiment_classifier(tweet_list)), pd.DataFrame(topic_classifier(tweet_list))
43
-
44
- sentiment.rename(columns={'score':'sentiment_confidence','label':'sentiment'}, inplace=True)
45
-
46
- topic.rename(columns={'score':'topic_confidence','label':'topic'}, inplace=True)
47
-
48
- df_group = pd.concat([df_merged,sentiment,topic],axis=1)
49
-
50
- df_group[['sentiment_confidence','topic_confidence']] = df_group[['sentiment_confidence','topic_confidence']].round(2).mul(100)
51
 
52
- df_tweets = df_group[['creation_time','username','tweet','sentiment','topic','sentiment_confidence','topic_confidence']]
53
-
54
- df_tweets = df_tweets.sort_values(by=['creation_time'],ascending=False)
55
-
56
- return df_tweets
57
 
 
 
58
 
 
 
 
59
 
60
  sentiment_classifier, topic_classifier = load_models()
61
 
 
10
  import plotly.graph_objects as go
11
  from datetime import datetime as dt
12
  from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
13
+ from datasets import Dataset
14
+ from huggingface_hub import Repository
15
 
16
  st.set_page_config(
17
  page_title="Live FinTwitter Analysis",
 
22
  st.sidebar.header("Sentiment Analysis Score")
23
 
24
  extract_time = dt.strftime(dt.today(),"%d_%B_%y_%H_%M")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ DATASET_REPO_URL = "https://huggingface.co/datasets/nickmuchi/fin_tweets"
 
 
 
 
27
 
28
+ DATA_FILENAME = "tweets_data.csv"
29
+ DATA_FILE = os.path.join("data", DATA_FILENAME)
30
 
31
+ repo = Repository(
32
+ local_dir="tweets", clone_from=DATASET_REPO_URL
33
+ )
34
 
35
  sentiment_classifier, topic_classifier = load_models()
36