Spaces:
Runtime error
Runtime error
Update app.py
Browse filesadded a new tool: get_hugging_face_top_daily_paper
app.py
CHANGED
|
@@ -7,6 +7,9 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -33,6 +36,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from bs4 import BeautifulSoup
|
| 11 |
+
import json
|
| 12 |
+
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
| 39 |
+
@tool #added
|
| 40 |
+
def get_hugging_face_top_daily_paper() -> str:
|
| 41 |
+
"""
|
| 42 |
+
This is a tool that returns the most upvoted paper on Hugging Face daily papers.
|
| 43 |
+
It returns the title of the paper
|
| 44 |
+
"""
|
| 45 |
+
try:
|
| 46 |
+
url = "<https://huggingface.co/papers>"
|
| 47 |
+
response = requests.get(url)
|
| 48 |
+
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
|
| 49 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
| 50 |
+
|
| 51 |
+
# Extract the title element from the JSON-like data in the "data-props" attribute
|
| 52 |
+
containers = soup.find_all('div', class_='SVELTE_HYDRATER contents')
|
| 53 |
+
top_paper = ""
|
| 54 |
+
|
| 55 |
+
for container in containers:
|
| 56 |
+
data_props = container.get('data-props', '')
|
| 57 |
+
if data_props:
|
| 58 |
+
try:
|
| 59 |
+
# Parse the JSON-like string
|
| 60 |
+
json_data = json.loads(data_props.replace('"', '"'))
|
| 61 |
+
if 'dailyPapers' in json_data:
|
| 62 |
+
top_paper = json_data['dailyPapers'][0]['title']
|
| 63 |
+
except json.JSONDecodeError:
|
| 64 |
+
continue
|
| 65 |
+
|
| 66 |
+
return top_paper
|
| 67 |
+
except requests.exceptions.RequestException as e:
|
| 68 |
+
print(f"Error occurred while fetching the HTML: {e}")
|
| 69 |
+
return None
|
| 70 |
|
| 71 |
final_answer = FinalAnswerTool()
|
| 72 |
|
|
|
|
| 89 |
|
| 90 |
agent = CodeAgent(
|
| 91 |
model=model,
|
| 92 |
+
tools=[get_hugging_face_top_daily_paper], ## add your tools here (don't remove final answer) #1-final_answer #2-image_generation_tool #3-
|
| 93 |
max_steps=6,
|
| 94 |
verbosity_level=1,
|
| 95 |
grammar=None,
|