Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,43 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +82,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from googleapiclient.discovery import build
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
import uuid
|
| 13 |
+
|
| 14 |
+
# Google Books API setup
|
| 15 |
+
google_api_key = os.getenv("AIzaSyDOxfDDznu39CSWR3wlGK-eEV2XH2zoGf4")
|
| 16 |
+
books_service = build("books", "v1", developerKey=google_api_key)
|
| 17 |
+
|
| 18 |
+
# I want to try connect to a google API to get some recommendation of audiobooks!
|
| 19 |
@tool
|
| 20 |
+
def search_audiobooks(topic:str, limit:int=3)-> str: #it's import to specify the return type
|
| 21 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 22 |
+
"""The tool is designed to connect to the google API platform and retrieve some audiobooks recommendations
|
| 23 |
Args:
|
| 24 |
+
topic: the topic that I would like to use to retieve some audiobooks
|
| 25 |
+
limit: it is a constant as I want to recommend only three audiobooks
|
| 26 |
"""
|
| 27 |
+
request = books_service.volumes().list(
|
| 28 |
+
q=f"subject:{topic}+audiobook",
|
| 29 |
+
maxResults=limit,
|
| 30 |
+
printType="books",
|
| 31 |
+
gl="us"
|
| 32 |
+
)
|
| 33 |
+
response = request.execute()
|
| 34 |
+
audiobooks = []
|
| 35 |
+
for item in response.get("items", []):
|
| 36 |
+
volume_info = item.get("volumeInfo", {})
|
| 37 |
+
# Check if audiobook (based on categories or accessInfo)
|
| 38 |
+
if "Audiobook" in volume_info.get("categories", []) or volume_info.get("accessInfo", {}).get("epub", {}).get("isAvailable", False):
|
| 39 |
+
audiobooks.append({
|
| 40 |
+
"title": volume_info.get("title", "Unknown"),
|
| 41 |
+
"author": ", ".join(volume_info.get("authors", ["Unknown"])),
|
| 42 |
+
"categories": ", ".join(volume_info.get("categories", ["Unknown"])),
|
| 43 |
+
"url": volume_info.get("canonicalVolumeLink", "#"),
|
| 44 |
+
"estimated_minutes": volume_info.get("pageCount", 180) # Estimate: 1 page ≈ 1 minute
|
| 45 |
+
})
|
| 46 |
+
return audiobooks
|
| 47 |
|
| 48 |
@tool
|
| 49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 82 |
|
| 83 |
agent = CodeAgent(
|
| 84 |
model=model,
|
| 85 |
+
tools=[final_answer,search_audiobooks,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 86 |
max_steps=6,
|
| 87 |
verbosity_level=1,
|
| 88 |
grammar=None,
|