amitbhatt6075 commited on
Commit
7cb42ac
·
1 Parent(s): fe0e9a4

fix: Remove dotenv and rely only on Hugging Face secrets

Browse files
Files changed (1) hide show
  1. core/thunderbird_engine.py +14 -15
core/thunderbird_engine.py CHANGED
@@ -4,9 +4,8 @@ import joblib
4
  import json
5
  from datetime import datetime
6
  from typing import Dict, Any, Optional
7
- from dotenv import load_dotenv
8
 
9
- # --- STABLE IMPORTS ---
10
  try:
11
  from newsapi import NewsApiClient
12
  except ImportError:
@@ -17,26 +16,26 @@ try:
17
  except ImportError:
18
  get_supabase_client = None
19
 
20
- # === THE FIX: LOAD .env FILE EXPLICITLY ===
21
- # Find the root directory (ai-service-deploy) and load the .env file from there.
22
- ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
23
- load_dotenv(dotenv_path=os.path.join(ROOT_DIR, '.env'))
24
- # ==========================================
25
-
26
- # --- CONFIGURATION ---
27
  MODEL_PATH = os.path.join(os.path.dirname(__file__), '..', 'models', 'thunderbird_market_predictor_v1.joblib')
28
- NEWS_API_KEY = os.getenv("NEWS_API_KEY") # Ab ye .env file se key uthayega
29
 
30
  def get_external_trends() -> dict:
31
  """
32
- STABLE VERSION: Fetches only from reliable sources (NewsAPI).
33
  """
34
- print("🚀 [Thunderbird Engine] Fetching trends (Stable Mode)...")
35
- results = { "news_headlines": [], "breakout_keyword": None, "trending_audio": None, "platform_shifts": None }
 
 
 
 
 
36
 
 
37
  if NEWS_API_KEY and NewsApiClient:
38
  try:
39
- print(" - ✅ NEWS_API_KEY found. Attempting to fetch headlines...")
40
  newsapi = NewsApiClient(api_key=NEWS_API_KEY)
41
  top_headlines = newsapi.get_everything(q='("influencer marketing")', language='en', sort_by='relevancy', page_size=5)
42
  if top_headlines.get('articles'):
@@ -45,7 +44,7 @@ def get_external_trends() -> dict:
45
  except Exception as e:
46
  print(f" - ⚠️ NewsAPI call failed: {e}")
47
  else:
48
- print(" - ℹ️ NEWS_API_KEY not found in .env file. Skipping headlines.")
49
 
50
  return results
51
 
 
4
  import json
5
  from datetime import datetime
6
  from typing import Dict, Any, Optional
 
7
 
8
+ # --- STABLE IMPORTS (No dotenv) ---
9
  try:
10
  from newsapi import NewsApiClient
11
  except ImportError:
 
16
  except ImportError:
17
  get_supabase_client = None
18
 
19
+ # --- CONFIGURATION (Directly from OS/Secrets) ---
 
 
 
 
 
 
20
  MODEL_PATH = os.path.join(os.path.dirname(__file__), '..', 'models', 'thunderbird_market_predictor_v1.joblib')
21
+ NEWS_API_KEY = os.environ.get("NEWS_API_KEY") # THIS WILL NOW READ FROM HUGGING FACE SECRETS
22
 
23
  def get_external_trends() -> dict:
24
  """
25
+ STABLE VERSION: Fetches only from reliable sources (NewsAPI via HF Secrets).
26
  """
27
+ print("🚀 [Thunderbird Engine] Fetching trends (Stable Mode, from HF Secrets)...")
28
+ results = {
29
+ "news_headlines": [],
30
+ "breakout_keyword": None,
31
+ "trending_audio": None,
32
+ "platform_shifts": None
33
+ }
34
 
35
+ # NewsAPI Logic
36
  if NEWS_API_KEY and NewsApiClient:
37
  try:
38
+ print(" - ✅ NEWS_API_KEY found in server secrets. Attempting fetch...")
39
  newsapi = NewsApiClient(api_key=NEWS_API_KEY)
40
  top_headlines = newsapi.get_everything(q='("influencer marketing")', language='en', sort_by='relevancy', page_size=5)
41
  if top_headlines.get('articles'):
 
44
  except Exception as e:
45
  print(f" - ⚠️ NewsAPI call failed: {e}")
46
  else:
47
+ print(" - ℹ️ NEWS_API_KEY not found in Hugging Face secrets. Skipping headlines.")
48
 
49
  return results
50