Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,16 @@ import os
|
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
-
|
6 |
|
7 |
-
# Fetch the
|
8 |
-
|
9 |
|
10 |
# Check if the API key is available, if not show an error and stop
|
11 |
-
if not
|
12 |
-
st.error("
|
13 |
st.stop()
|
14 |
|
15 |
-
# Initialize the GROQ client with the fetched API key
|
16 |
-
# try:
|
17 |
-
# groq_client = Groq(api_key=groq_api_key)
|
18 |
-
# except Exception as e:
|
19 |
-
# st.error(f"Error initializing GROQ client: {e}")
|
20 |
-
# st.stop()
|
21 |
-
|
22 |
# Function to load and preprocess data
|
23 |
@st.cache_data
|
24 |
def load_data(file):
|
@@ -51,17 +44,16 @@ def provide_observed_advice(data):
|
|
51 |
|
52 |
return advice
|
53 |
|
54 |
-
# Function to fetch health articles from
|
55 |
def get_health_articles(query):
|
56 |
-
url = f"https://
|
57 |
-
|
58 |
-
|
59 |
try:
|
60 |
-
response = requests.get(url
|
61 |
response.raise_for_status() # This will raise an HTTPError for bad responses
|
62 |
data = response.json() # Assuming the API returns JSON
|
63 |
-
if '
|
64 |
-
articles = [{"title": item["title"], "url": item["url"]} for item in data['
|
65 |
else:
|
66 |
articles = []
|
67 |
return articles
|
|
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import requests
|
5 |
+
import urllib.parse
|
6 |
|
7 |
+
# Fetch the News API key from the environment variable
|
8 |
+
news_api_key = "fe1e6bcbbf384b3e9220a7a1138805e0" # Replace with your News API key
|
9 |
|
10 |
# Check if the API key is available, if not show an error and stop
|
11 |
+
if not news_api_key:
|
12 |
+
st.error("NEWS_API_KEY is not set. Please provide a valid API key.")
|
13 |
st.stop()
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Function to load and preprocess data
|
16 |
@st.cache_data
|
17 |
def load_data(file):
|
|
|
44 |
|
45 |
return advice
|
46 |
|
47 |
+
# Function to fetch health articles from News API based on the query
|
48 |
def get_health_articles(query):
|
49 |
+
url = f"https://newsapi.org/v2/everything?q={query}&apiKey={news_api_key}"
|
50 |
+
|
|
|
51 |
try:
|
52 |
+
response = requests.get(url)
|
53 |
response.raise_for_status() # This will raise an HTTPError for bad responses
|
54 |
data = response.json() # Assuming the API returns JSON
|
55 |
+
if 'articles' in data:
|
56 |
+
articles = [{"title": item["title"], "url": item["url"]} for item in data['articles']]
|
57 |
else:
|
58 |
articles = []
|
59 |
return articles
|