RafaelAgreda commited on
Commit
cab0d6a
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -7
app.py CHANGED
@@ -4,19 +4,157 @@ import requests
4
  import pytz
5
  import yaml
6
  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
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
+ # to use spotify API
9
+ import spotipy
10
+ from spotipy.oauth2 import SpotifyClientCredentials
11
+
12
 
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
+ # The next step should be connect directly to a spotify API for example or Audible API, but let's keep it simple for now.
15
  @tool
16
+ def get_audiobook_recommendation(category=None):
17
+ """
18
+ Tool function that recommends audiobooks based on specified category.
19
+
20
  Args:
21
+ category (str, optional): Genre or topic of interest. If None, returns a random recommendation.
22
+
23
+ Returns:
24
+ dict: Audiobook recommendation with title, author, and description
25
  """
26
+ import random
27
+
28
+ # Audiobook catalog organized by category
29
+ audiobook_catalog = {
30
+ "science fiction": [
31
+ {
32
+ "title": "Dune",
33
+ "author": "Frank Herbert",
34
+ "narrator": "Simon Vance",
35
+ "length": "21h 8m",
36
+ "description": "An epic science fiction novel about politics, religion, and ecology on a desert planet."
37
+ },
38
+ {
39
+ "title": "Project Hail Mary",
40
+ "author": "Andy Weir",
41
+ "narrator": "Ray Porter",
42
+ "length": "16h 10m",
43
+ "description": "A lone astronaut must save humanity from an extinction-level threat using his scientific ingenuity."
44
+ }
45
+ ],
46
+ "fantasy": [
47
+ {
48
+ "title": "The Name of the Wind",
49
+ "author": "Patrick Rothfuss",
50
+ "narrator": "Nick Podehl",
51
+ "length": "27h 55m",
52
+ "description": "First book in the Kingkiller Chronicle, following the magical journey of Kvothe."
53
+ },
54
+ {
55
+ "title": "The Hobbit",
56
+ "author": "J.R.R. Tolkien",
57
+ "narrator": "Andy Serkis",
58
+ "length": "10h 25m",
59
+ "description": "Bilbo Baggins' unexpected adventure with dwarves and a dragon that changed Middle-earth."
60
+ }
61
+ ],
62
+ "mystery": [
63
+ {
64
+ "title": "The Thursday Murder Club",
65
+ "author": "Richard Osman",
66
+ "narrator": "Lesley Manville",
67
+ "length": "12h 25m",
68
+ "description": "Four septuagenarians meet weekly to solve cold cases, until a live murder occurs right on their doorstep."
69
+ },
70
+ {
71
+ "title": "The Silent Patient",
72
+ "author": "Alex Michaelides",
73
+ "narrator": "Jack Hawkins",
74
+ "length": "8h 43m",
75
+ "description": "A psychological thriller about a woman who shoots her husband and then never speaks again."
76
+ }
77
+ ],
78
+ "business": [
79
+ {
80
+ "title": "Never Split the Difference",
81
+ "author": "Chris Voss",
82
+ "narrator": "Michael Kramer",
83
+ "length": "8h 7m",
84
+ "description": "Negotiation tactics from a former FBI hostage negotiator."
85
+ },
86
+ {
87
+ "title": "Atomic Habits",
88
+ "author": "James Clear",
89
+ "narrator": "James Clear",
90
+ "length": "5h 35m",
91
+ "description": "A practical guide to building good habits and breaking bad ones."
92
+ }
93
+ ],
94
+ "history": [
95
+ {
96
+ "title": "Sapiens: A Brief History of Humankind",
97
+ "author": "Yuval Noah Harari",
98
+ "narrator": "Derek Perkins",
99
+ "length": "15h 18m",
100
+ "description": "An exploration of human history from ancient humans to the present day."
101
+ },
102
+ {
103
+ "title": "The Splendid and the Vile",
104
+ "author": "Erik Larson",
105
+ "narrator": "John Lee",
106
+ "length": "17h 49m",
107
+ "description": "Chronicles Winston Churchill's first year as Prime Minister during the Blitz."
108
+ }
109
+ ],
110
+ "self-improvement": [
111
+ {
112
+ "title": "Thinking, Fast and Slow",
113
+ "author": "Daniel Kahneman",
114
+ "narrator": "Patrick Egan",
115
+ "length": "20h 2m",
116
+ "description": "Explores the two systems that drive how we think and make decisions."
117
+ },
118
+ {
119
+ "title": "The Power of Now",
120
+ "author": "Eckhart Tolle",
121
+ "narrator": "Eckhart Tolle",
122
+ "length": "7h 37m",
123
+ "description": "A guide to spiritual enlightenment and living in the present moment."
124
+ }
125
+ ]
126
+ }
127
+
128
+ # Normalize category input if provided
129
+ if category:
130
+ category = category.lower().strip()
131
+
132
+ # Check if category exists in catalog
133
+ if category not in audiobook_catalog:
134
+ # Try partial matching
135
+ matching_categories = [cat for cat in audiobook_catalog.keys() if category in cat]
136
+
137
+ if matching_categories:
138
+ category = matching_categories[0]
139
+ else:
140
+ # Return message if no matching category
141
+ all_books = [book for booklist in audiobook_catalog.values() for book in booklist]
142
+ recommendation = random.choice(all_books)
143
+ return {
144
+ "result": recommendation,
145
+ "message": f"No exact match for '{category}'. Here's a random recommendation instead."
146
+ }
147
+ else:
148
+ # If no category specified, choose random category
149
+ category = random.choice(list(audiobook_catalog.keys()))
150
+
151
+ # Select a random book from the category
152
+ recommendation = random.choice(audiobook_catalog[category])
153
+
154
+ return {
155
+ "result": recommendation,
156
+ "message": f"Here's a {category} audiobook recommendation for you!"
157
+ }
158
 
159
  @tool
160
  def get_current_time_in_timezone(timezone: str) -> str: