Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,9 @@ import daal4py as d4p
|
|
9 |
|
10 |
# Twitter API setup
|
11 |
def twitter_api_setup():
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
access_token_secret = 'YOUR_TWITTER_ACCESS_SECRET'
|
16 |
-
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
|
17 |
-
auth.set_access_token(access_token, access_token_secret)
|
18 |
-
api = tweepy.API(auth)
|
19 |
-
return api
|
20 |
|
21 |
# YouTube API setup
|
22 |
def youtube_api_setup():
|
@@ -25,13 +20,17 @@ def youtube_api_setup():
|
|
25 |
return youtube
|
26 |
|
27 |
# Fetch Twitter sentiment
|
28 |
-
def fetch_twitter_sentiment(symbol,
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
sentiments = sentiment_model(tweet_texts)
|
32 |
sentiment_scores = [s['label'] for s in sentiments]
|
33 |
positive = sentiment_scores.count('POSITIVE')
|
34 |
negative = sentiment_scores.count('NEGATIVE')
|
|
|
35 |
return positive, negative
|
36 |
|
37 |
# Fetch YouTube sentiment
|
@@ -84,8 +83,8 @@ def main():
|
|
84 |
|
85 |
# Twitter Sentiment
|
86 |
st.subheader("Twitter Sentiment Analysis")
|
87 |
-
|
88 |
-
positive_twitter, negative_twitter = fetch_twitter_sentiment(stock_symbol,
|
89 |
st.write(f"Positive Tweets: {positive_twitter}, Negative Tweets: {negative_twitter}")
|
90 |
|
91 |
# YouTube Sentiment
|
@@ -118,3 +117,4 @@ def main():
|
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
main()
|
|
|
|
9 |
|
10 |
# Twitter API setup
|
11 |
def twitter_api_setup():
|
12 |
+
bearer_token = 'YOUR_TWITTER_BEARER_TOKEN'
|
13 |
+
client = tweepy.Client(bearer_token=bearer_token)
|
14 |
+
return client
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# YouTube API setup
|
17 |
def youtube_api_setup():
|
|
|
20 |
return youtube
|
21 |
|
22 |
# Fetch Twitter sentiment
|
23 |
+
def fetch_twitter_sentiment(symbol, client, sentiment_model):
|
24 |
+
query = f"{symbol} -is:retweet lang:en"
|
25 |
+
tweets = client.search_recent_tweets(query=query, max_results=100, tweet_fields=['text'])
|
26 |
+
|
27 |
+
tweet_texts = [tweet.text for tweet in tweets.data] if tweets.data else []
|
28 |
+
|
29 |
sentiments = sentiment_model(tweet_texts)
|
30 |
sentiment_scores = [s['label'] for s in sentiments]
|
31 |
positive = sentiment_scores.count('POSITIVE')
|
32 |
negative = sentiment_scores.count('NEGATIVE')
|
33 |
+
|
34 |
return positive, negative
|
35 |
|
36 |
# Fetch YouTube sentiment
|
|
|
83 |
|
84 |
# Twitter Sentiment
|
85 |
st.subheader("Twitter Sentiment Analysis")
|
86 |
+
client = twitter_api_setup()
|
87 |
+
positive_twitter, negative_twitter = fetch_twitter_sentiment(stock_symbol, client, sentiment_model)
|
88 |
st.write(f"Positive Tweets: {positive_twitter}, Negative Tweets: {negative_twitter}")
|
89 |
|
90 |
# YouTube Sentiment
|
|
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
main()
|
120 |
+
|