Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 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 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
-
return
|
| 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('"', '"'))
|
| 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
|