zvl commited on
Commit
94ad18c
·
verified ·
1 Parent(s): 895dd79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -9,11 +9,14 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def buscar_datos_gob(term: str, page_size: int, page: int, sort: str) -> dict:
13
- """A tool that searches for datasets in the API of datos.gob.es.
 
14
 
15
  Args:
16
  term: The search term to filter the datasets.
 
 
17
  page_size: The number of results per page (maximum: 50).
18
  page: The page number for pagination of results.
19
  sort: The field by which to sort the results.
@@ -21,18 +24,25 @@ def buscar_datos_gob(term: str, page_size: int, page: int, sort: str) -> dict:
21
  Returns:
22
  A dictionary containing the search results from the datos.gob.es API.
23
  """
 
 
24
  base_url = "https://datos.gob.es/apidata/catalog/dataset"
 
 
 
 
25
  params = {
26
  "q": term,
27
  "_pageSize": page_size,
28
  "_page": page,
29
  "_sort": sort
30
  }
 
31
  headers = {
32
- "Accept": "application/json",
33
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
34
  }
35
-
36
  try:
37
  response = requests.get(base_url, params=params, headers=headers)
38
  response.raise_for_status()
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def buscar_datos_gob(term: str, category: str = None, format: str = "json", page_size: int = 10, page: int = 0, sort: str = "title") -> dict:
13
+ """
14
+ A tool that searches for datasets in the datos.gob.es API.
15
 
16
  Args:
17
  term: The search term to filter the datasets.
18
+ category: The category/topic to filter datasets (e.g., "hacienda").
19
+ format: The format of the datasets (json, xml, csv, rdf). Default is json.
20
  page_size: The number of results per page (maximum: 50).
21
  page: The page number for pagination of results.
22
  sort: The field by which to sort the results.
 
24
  Returns:
25
  A dictionary containing the search results from the datos.gob.es API.
26
  """
27
+ import requests
28
+
29
  base_url = "https://datos.gob.es/apidata/catalog/dataset"
30
+
31
+ if category:
32
+ base_url += f"/theme/{category}"
33
+
34
  params = {
35
  "q": term,
36
  "_pageSize": page_size,
37
  "_page": page,
38
  "_sort": sort
39
  }
40
+
41
  headers = {
42
+ "Accept": f"application/{format}",
43
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
44
  }
45
+
46
  try:
47
  response = requests.get(base_url, params=params, headers=headers)
48
  response.raise_for_status()