BioCodeFusion commited on
Commit
f39f9e7
·
verified ·
1 Parent(s): 0f6f64b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -16
app.py CHANGED
@@ -18,27 +18,57 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
21
  @tool
22
- def grocery_info(grocery_id:int) -> str:
23
- """A tool that fetches the grocery information from the Swedish Food Agency api
24
- Args:
25
- grocery_id: The id of the grocery (e.g, and int expected)
26
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- base_url = "https://dataportal.livsmedelsverket.se/livsmedel"
29
- grocery_api_url = f"{base_url}/api/v1/livsmedel/{grocery_id}?sprak=2"
30
-
31
- response = requests.get(grocery_api_url)
32
- data = response.json()
33
 
34
- if response.status_code == 200:
35
- data = response.json()
36
- grocery_description = data.get("namn")
37
- grocery_ingredients = data.get("links")[2]['href']
38
- return grocery_description, grocery_ingredients_link
 
 
 
39
  else:
40
- return "Error: Unable to find grocery data."
41
-
42
 
43
 
44
  @tool
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ from bs4 import BeautifulSoup
22
+ import json
23
+
24
  @tool
25
+ def get_hugging_face_top_daily_paper() -> str:
 
 
 
26
  """
27
+ This is a tool that returns the most upvoted paper on Hugging Face daily papers.
28
+ It returns the title of the paper
29
+ """
30
+ try:
31
+ url = "<https://huggingface.co/papers>"
32
+ response = requests.get(url)
33
+ response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
34
+ soup = BeautifulSoup(response.content, "html.parser")
35
+
36
+ # Extract the title element from the JSON-like data in the "data-props" attribute
37
+ containers = soup.find_all('div', class_='SVELTE_HYDRATER contents')
38
+ top_paper = ""
39
+
40
+ for container in containers:
41
+ data_props = container.get('data-props', '')
42
+ if data_props:
43
+ try:
44
+ # Parse the JSON-like string
45
+ json_data = json.loads(data_props.replace('&quot;', '"'))
46
+ if 'dailyPapers' in json_data:
47
+ top_paper = json_data['dailyPapers'][0]['title']
48
+ except json.JSONDecodeError:
49
+ continue
50
+
51
+ return top_paper
52
+ except requests.exceptions.RequestException as e:
53
+ print(f"Error occurred while fetching the HTML: {e}")
54
+ return None
55
 
56
+ @tool
57
+ def get_paper_id_by_title(title: str) -> str:
58
+ """
59
+ This is a tool that returns the arxiv paper id by its title.
60
+ It returns the title of the paper
61
 
62
+ Args:
63
+ title: The paper title for which to get the id.
64
+ """
65
+ api = HfApi()
66
+ papers = api.list_papers(query=title)
67
+ if papers:
68
+ paper = next(iter(papers))
69
+ return paper.id
70
  else:
71
+ return None
 
72
 
73
 
74
  @tool