Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,18 +3,17 @@ import pandas as pd
|
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import nltk
|
| 6 |
-
import
|
| 7 |
-
from io import BytesIO
|
| 8 |
-
import base64
|
| 9 |
-
import plotly.express as px
|
| 10 |
-
from wordcloud import WordCloud
|
| 11 |
from textblob import TextBlob
|
| 12 |
-
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
| 13 |
from transformers import pipeline
|
| 14 |
-
from
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
import praw
|
|
|
|
| 17 |
from sklearn.linear_model import Ridge
|
|
|
|
| 18 |
|
| 19 |
# --------------------------
|
| 20 |
# Initial Setup
|
|
@@ -33,7 +32,7 @@ st.set_page_config(
|
|
| 33 |
# --------------------------
|
| 34 |
|
| 35 |
class Config:
|
| 36 |
-
# Replace
|
| 37 |
YOUTUBE_API_KEY = os.getenv("YT_API_KEY", "your_youtube_api_key_here")
|
| 38 |
REDDIT_CLIENT_ID = os.getenv("REDDIT_CLIENT_ID", "your_reddit_client_id")
|
| 39 |
REDDIT_CLIENT_SECRET = os.getenv("REDDIT_CLIENT_SECRET", "your_reddit_secret")
|
|
@@ -52,9 +51,8 @@ class Config:
|
|
| 52 |
|
| 53 |
def initialize_resources():
|
| 54 |
"""Initialize all required resources with proper error handling"""
|
| 55 |
-
|
| 56 |
-
# Setup NLTK
|
| 57 |
try:
|
|
|
|
| 58 |
os.makedirs(Config.NLTK_DATA_PATH, exist_ok=True)
|
| 59 |
nltk.data.path.append(Config.NLTK_DATA_PATH)
|
| 60 |
|
|
@@ -195,13 +193,6 @@ def fetch_youtube_data(keyword, max_results=25):
|
|
| 195 |
|
| 196 |
return pd.DataFrame(data)
|
| 197 |
|
| 198 |
-
except HttpError as e:
|
| 199 |
-
if e.resp.status == 403:
|
| 200 |
-
st.error("YouTube API quota exceeded. Try again later.")
|
| 201 |
-
else:
|
| 202 |
-
st.error(f"YouTube API error: {str(e)}")
|
| 203 |
-
return pd.DataFrame()
|
| 204 |
-
|
| 205 |
except Exception as e:
|
| 206 |
st.error(f"Error fetching YouTube data: {str(e)}")
|
| 207 |
return pd.DataFrame()
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import nltk
|
| 6 |
+
from nltk.sentiment import SentimentIntensityAnalyzer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from textblob import TextBlob
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
+
from wordcloud import WordCloud
|
| 10 |
+
import base64
|
| 11 |
+
from io import BytesIO
|
| 12 |
+
import plotly.express as px
|
| 13 |
import praw
|
| 14 |
+
from googleapiclient.discovery import build
|
| 15 |
from sklearn.linear_model import Ridge
|
| 16 |
+
import os
|
| 17 |
|
| 18 |
# --------------------------
|
| 19 |
# Initial Setup
|
|
|
|
| 32 |
# --------------------------
|
| 33 |
|
| 34 |
class Config:
|
| 35 |
+
# API Keys - Replace with your actual keys or use environment variables
|
| 36 |
YOUTUBE_API_KEY = os.getenv("YT_API_KEY", "your_youtube_api_key_here")
|
| 37 |
REDDIT_CLIENT_ID = os.getenv("REDDIT_CLIENT_ID", "your_reddit_client_id")
|
| 38 |
REDDIT_CLIENT_SECRET = os.getenv("REDDIT_CLIENT_SECRET", "your_reddit_secret")
|
|
|
|
| 51 |
|
| 52 |
def initialize_resources():
|
| 53 |
"""Initialize all required resources with proper error handling"""
|
|
|
|
|
|
|
| 54 |
try:
|
| 55 |
+
# Setup NLTK data
|
| 56 |
os.makedirs(Config.NLTK_DATA_PATH, exist_ok=True)
|
| 57 |
nltk.data.path.append(Config.NLTK_DATA_PATH)
|
| 58 |
|
|
|
|
| 193 |
|
| 194 |
return pd.DataFrame(data)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
except Exception as e:
|
| 197 |
st.error(f"Error fetching YouTube data: {str(e)}")
|
| 198 |
return pd.DataFrame()
|