Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,11 +35,10 @@ from newsapi import NewsApiClient
|
|
| 35 |
# === CHANGES FOR DEPLOYMENT ===
|
| 36 |
# Use environment variables/secrets instead of hardcoded keys
|
| 37 |
# ---------------------------
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
NEWS_API_KEY_C = os.environ.get("NEWS_API_KEY_C")
|
| 43 |
|
| 44 |
MONGO_URI = os.environ.get("MONGO_URI", "")
|
| 45 |
|
|
@@ -196,18 +195,15 @@ def hf_post(url, api_key, text, timeout=30):
|
|
| 196 |
return {"error": f"JSON parse error: {e}", "raw": r.text}
|
| 197 |
|
| 198 |
def call_sentiment(text):
|
| 199 |
-
|
| 200 |
-
return hf_post(SENTIMENT_URL, SENTIMENT_API_KEY, text)
|
| 201 |
|
| 202 |
def call_fake_news(text):
|
| 203 |
-
|
| 204 |
-
return hf_post(FAKENEWS_URL, FAKENEWS_API_KEY, text)
|
| 205 |
|
| 206 |
# ---------------------------
|
| 207 |
# 7) Groq reasoning wrapper
|
| 208 |
# ---------------------------
|
| 209 |
-
|
| 210 |
-
groq_client = Groq(api_key=GROQ_API_KEY)
|
| 211 |
|
| 212 |
def get_groq_reasoning(text, prediction):
|
| 213 |
prompt = f"Text: {text}\nPrediction: {prediction}\nExplain in 2-4 clear sentences WHY this prediction makes sense (cite typical signals)."
|
|
@@ -228,8 +224,7 @@ def get_groq_reasoning(text, prediction):
|
|
| 228 |
# ---------------------------
|
| 229 |
# 8) NewsAPI helper (related articles)
|
| 230 |
# ---------------------------
|
| 231 |
-
|
| 232 |
-
newsapi_client = NewsApiClient(api_key=NEWS_API_KEY_C)
|
| 233 |
|
| 234 |
def fetch_related_articles(query, max_results=4):
|
| 235 |
if not newsapi_client:
|
|
|
|
| 35 |
# === CHANGES FOR DEPLOYMENT ===
|
| 36 |
# Use environment variables/secrets instead of hardcoded keys
|
| 37 |
# ---------------------------
|
| 38 |
+
SENTIMENT_KEY = os.environ.get("SENTIMENT_KEY")
|
| 39 |
+
FAKENEWS_KEY = os.environ.get("FAKENEWS_KEY")
|
| 40 |
+
GROQ_KEY = os.environ.get("GROQ_KEY")
|
| 41 |
+
NEWSAPI_KEY = os.environ.get("NEWSAPI_KEY")
|
|
|
|
| 42 |
|
| 43 |
MONGO_URI = os.environ.get("MONGO_URI", "")
|
| 44 |
|
|
|
|
| 195 |
return {"error": f"JSON parse error: {e}", "raw": r.text}
|
| 196 |
|
| 197 |
def call_sentiment(text):
|
| 198 |
+
return hf_post(SENTIMENT_URL, SENTIMENT_KEY, text)
|
|
|
|
| 199 |
|
| 200 |
def call_fake_news(text):
|
| 201 |
+
return hf_post(FAKENEWS_URL, FAKENEWS_KEY, text)
|
|
|
|
| 202 |
|
| 203 |
# ---------------------------
|
| 204 |
# 7) Groq reasoning wrapper
|
| 205 |
# ---------------------------
|
| 206 |
+
groq_client = Groq(api_key=GROQ_KEY)
|
|
|
|
| 207 |
|
| 208 |
def get_groq_reasoning(text, prediction):
|
| 209 |
prompt = f"Text: {text}\nPrediction: {prediction}\nExplain in 2-4 clear sentences WHY this prediction makes sense (cite typical signals)."
|
|
|
|
| 224 |
# ---------------------------
|
| 225 |
# 8) NewsAPI helper (related articles)
|
| 226 |
# ---------------------------
|
| 227 |
+
newsapi_client = NewsApiClient(api_key=NEWSAPI_KEY)
|
|
|
|
| 228 |
|
| 229 |
def fetch_related_articles(query, max_results=4):
|
| 230 |
if not newsapi_client:
|