Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,54 +21,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
21 |
from bs4 import BeautifulSoup
|
22 |
import json
|
23 |
|
24 |
-
|
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
|
58 |
"""
|
59 |
-
|
60 |
-
It returns the title of the paper
|
61 |
|
62 |
Args:
|
63 |
-
|
|
|
|
|
|
|
64 |
"""
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
return None
|
72 |
|
73 |
|
74 |
@tool
|
|
|
21 |
from bs4 import BeautifulSoup
|
22 |
import json
|
23 |
|
24 |
+
from transformers import tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
@tool
|
27 |
+
def is_prime(n: int) -> bool:
|
28 |
"""
|
29 |
+
Check if a number is a prime number.
|
|
|
30 |
|
31 |
Args:
|
32 |
+
n: The number to check.
|
33 |
+
|
34 |
+
Returns:
|
35 |
+
True if n is a prime number, False otherwise.
|
36 |
"""
|
37 |
+
if n < 2:
|
38 |
+
return False
|
39 |
+
for i in range(2, int(n**0.5) + 1):
|
40 |
+
if n % i == 0:
|
41 |
+
return False
|
42 |
+
return True
|
|
|
43 |
|
44 |
|
45 |
@tool
|