Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,50 +6,7 @@ import yaml
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from Gradio_UI import GradioUI # Assuming this is your custom module
|
8 |
|
9 |
-
from typing import Dict, Optional, TypedDict
|
10 |
-
import random
|
11 |
|
12 |
-
class AudiobookRecommendation(TypedDict):
|
13 |
-
title: str
|
14 |
-
author: str
|
15 |
-
narrator: str
|
16 |
-
length: str
|
17 |
-
description: str
|
18 |
-
|
19 |
-
@tool
|
20 |
-
def get_audiobook_recommendation(category: Optional[str] = None) -> AudiobookRecommendation:
|
21 |
-
"""
|
22 |
-
Returns a single audiobook recommendation based on a category.
|
23 |
-
|
24 |
-
Args:
|
25 |
-
category (Optional[str]): The genre or topic of interest for the audiobook recommendation.
|
26 |
-
If None, a random category is chosen.
|
27 |
-
|
28 |
-
Returns:
|
29 |
-
AudiobookRecommendation: A dictionary containing the audiobook's title, author, narrator,
|
30 |
-
length, and description.
|
31 |
-
"""
|
32 |
-
audiobook_catalog = {
|
33 |
-
"science fiction": [
|
34 |
-
{"title": "Dune", "author": "Frank Herbert", "narrator": "Simon Vance", "length": "21h 8m", "description": "An epic science fiction novel about politics, religion, and ecology on a desert planet."},
|
35 |
-
{"title": "Project Hail Mary", "author": "Andy Weir", "narrator": "Ray Porter", "length": "16h 10m", "description": "A lone astronaut must save humanity..."}
|
36 |
-
],
|
37 |
-
"fantasy": [
|
38 |
-
{"title": "The Hobbit", "author": "J.R.R. Tolkien", "narrator": "Andy Serkis", "length": "10h 25m", "description": "Bilbo Baggins' unexpected adventure..."}
|
39 |
-
],
|
40 |
-
# Add more categories as needed
|
41 |
-
}
|
42 |
-
|
43 |
-
try:
|
44 |
-
if category is not None:
|
45 |
-
category = category.lower().strip()
|
46 |
-
if category in audiobook_catalog:
|
47 |
-
return random.choice(audiobook_catalog[category])
|
48 |
-
random_category = random.choice(list(audiobook_catalog.keys()))
|
49 |
-
return random.choice(audiobook_catalog[random_category])
|
50 |
-
except Exception as e:
|
51 |
-
all_books = [book for books in audiobook_catalog.values() for book in books]
|
52 |
-
return random.choice(all_books)
|
53 |
|
54 |
@tool
|
55 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from Gradio_UI import GradioUI # Assuming this is your custom module
|
8 |
|
|
|
|
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
@tool
|
12 |
def get_current_time_in_timezone(timezone: str) -> str:
|