saherPervaiz commited on
Commit
aafbea1
·
verified ·
1 Parent(s): 1829428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -6,9 +6,6 @@ from groq import Groq
6
  # Set the API key directly or from environment variable
7
  api_key = "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" # Replace with your actual demo API key
8
 
9
- # Initialize the Groq client with the API key
10
- client = Groq(api_key=api_key)
11
-
12
  # Function to load and preprocess data
13
  @st.cache_data
14
  def load_data(file):
@@ -47,14 +44,13 @@ def get_health_articles(query):
47
  headers = {"Authorization": f"Bearer {api_key}"} # Use the demo API key in the header
48
 
49
  try:
50
- response = requests.get(url, headers=headers)
51
  response.raise_for_status() # This will raise an HTTPError for bad responses
52
  data = response.json() # Assuming the API returns JSON
53
  if 'results' in data:
54
- articles = [{"title": item["title"], "url": item["url"]} for item in data['results']]
55
  else:
56
- articles = []
57
- return articles
58
  except requests.exceptions.HTTPError as http_err:
59
  st.error(f"HTTP error occurred: {http_err}. Please check your API key and the endpoint.")
60
  st.error(f"Response content: {response.text}")
 
6
  # Set the API key directly or from environment variable
7
  api_key = "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" # Replace with your actual demo API key
8
 
 
 
 
9
  # Function to load and preprocess data
10
  @st.cache_data
11
  def load_data(file):
 
44
  headers = {"Authorization": f"Bearer {api_key}"} # Use the demo API key in the header
45
 
46
  try:
47
+ response = requests.get(url, headers=headers, timeout=10) # Timeout after 10 seconds
48
  response.raise_for_status() # This will raise an HTTPError for bad responses
49
  data = response.json() # Assuming the API returns JSON
50
  if 'results' in data:
51
+ return [{"title": item["title"], "url": item["url"]} for item in data['results']]
52
  else:
53
+ return []
 
54
  except requests.exceptions.HTTPError as http_err:
55
  st.error(f"HTTP error occurred: {http_err}. Please check your API key and the endpoint.")
56
  st.error(f"Response content: {response.text}")