Tesvia commited on
Commit
748af90
·
verified ·
1 Parent(s): f98cfc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -11,27 +11,25 @@ from Gradio_UI import GradioUI
11
  @tool
12
  def get_local_news_headlines(location: str) -> str:
13
  """
14
- A tool that fetches top local news headlines for a given location using NewsAPI.
15
-
16
  Args:
17
  location: The name of the location or a keyword for the news.
18
-
19
  Returns:
20
  A string with the top headlines or an error message.
21
  """
22
  import requests
23
  try:
24
- url = "https://newsapi.org/v2/top-headlines"
25
  params = {
26
- "q": location,
27
- "apiKey": "0706f91fde884dd399832d9fde764f89", # Replace with your actual NewsAPI key
28
  "language": "en",
29
- "pageSize": 5 # Limit to 5 headlines
 
30
  }
31
  response = requests.get(url, params=params)
32
  data = response.json()
33
  if data.get("status") == "ok":
34
- headlines = [article["title"] for article in data.get("articles", [])]
35
  if headlines:
36
  return f"Top headlines in {location}:\n" + "\n".join(headlines)
37
  else:
 
11
  @tool
12
  def get_local_news_headlines(location: str) -> str:
13
  """
14
+ A tool that fetches top local news headlines for a given location using Currents API.
 
15
  Args:
16
  location: The name of the location or a keyword for the news.
 
17
  Returns:
18
  A string with the top headlines or an error message.
19
  """
20
  import requests
21
  try:
22
+ url = "https://api.currentsapi.services/v1/search"
23
  params = {
24
+ "keywords": location,
 
25
  "language": "en",
26
+ "apiKey": "9kgcb14yVbcFQULH9tMpF-ZS0bDx9ISbP7oJEk_lcN7pbpWu",
27
+ "limit": 5 # Limit to 5 headlines
28
  }
29
  response = requests.get(url, params=params)
30
  data = response.json()
31
  if data.get("status") == "ok":
32
+ headlines = [article["title"] for article in data.get("news", [])]
33
  if headlines:
34
  return f"Top headlines in {location}:\n" + "\n".join(headlines)
35
  else: