Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,12 @@ def my_cutom_tool(arg1: str, arg2: int) -> str:
|
|
| 20 |
@tool
|
| 21 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 22 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 23 |
Args:
|
| 24 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
try:
|
| 27 |
tz = pytz.timezone(timezone)
|
|
@@ -84,7 +88,9 @@ def map_mood_to_params(mood: str, weather_condition: str = None) -> dict:
|
|
| 84 |
@tool
|
| 85 |
def get_user_location() -> str:
|
| 86 |
"""Fetches the user's location using ip-api.com.
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
"""
|
| 89 |
city, country, timezone = fetch_user_location_data()
|
| 90 |
if city and country and timezone:
|
|
@@ -94,8 +100,12 @@ def get_user_location() -> str:
|
|
| 94 |
@tool
|
| 95 |
def get_weather(city: str) -> str:
|
| 96 |
"""Fetches weather data for a given city using OpenWeatherMap API.
|
|
|
|
| 97 |
Args:
|
| 98 |
-
city: The city
|
|
|
|
|
|
|
|
|
|
| 99 |
"""
|
| 100 |
weather = fetch_weather_for_city(city)
|
| 101 |
if weather:
|
|
@@ -106,15 +116,24 @@ def get_weather(city: str) -> str:
|
|
| 106 |
def get_songs_by_mood(mood: str, local: bool = False) -> str:
|
| 107 |
"""Fetches a playlist of songs that fits the user's mood using Spotify's Recommendations API.
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
"""
|
| 119 |
weather_condition = None
|
| 120 |
if local:
|
|
|
|
| 20 |
@tool
|
| 21 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 22 |
"""A tool that fetches the current local time in a specified timezone.
|
| 23 |
+
|
| 24 |
Args:
|
| 25 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 26 |
+
|
| 27 |
+
Returns:
|
| 28 |
+
A string stating the current local time in the specified timezone.
|
| 29 |
"""
|
| 30 |
try:
|
| 31 |
tz = pytz.timezone(timezone)
|
|
|
|
| 88 |
@tool
|
| 89 |
def get_user_location() -> str:
|
| 90 |
"""Fetches the user's location using ip-api.com.
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
A string containing the city, country, and timezone, or an error message.
|
| 94 |
"""
|
| 95 |
city, country, timezone = fetch_user_location_data()
|
| 96 |
if city and country and timezone:
|
|
|
|
| 100 |
@tool
|
| 101 |
def get_weather(city: str) -> str:
|
| 102 |
"""Fetches weather data for a given city using OpenWeatherMap API.
|
| 103 |
+
|
| 104 |
Args:
|
| 105 |
+
city: The name of the city.
|
| 106 |
+
|
| 107 |
+
Returns:
|
| 108 |
+
A string describing the current weather in the specified city, or an error message.
|
| 109 |
"""
|
| 110 |
weather = fetch_weather_for_city(city)
|
| 111 |
if weather:
|
|
|
|
| 116 |
def get_songs_by_mood(mood: str, local: bool = False) -> str:
|
| 117 |
"""Fetches a playlist of songs that fits the user's mood using Spotify's Recommendations API.
|
| 118 |
|
| 119 |
+
Args:
|
| 120 |
+
mood: A string representing the desired mood (e.g., "happy", "sad", "energetic", "chill").
|
| 121 |
+
local: A boolean flag. If True, the tool fetches the user's location and current weather
|
| 122 |
+
to adjust the mood mapping accordingly.
|
| 123 |
+
|
| 124 |
+
Returns:
|
| 125 |
+
A string containing a playlist of songs (each on a new line) that matches the mood parameters.
|
| 126 |
|
| 127 |
+
Additional Details:
|
| 128 |
+
Mood is expressed in terms of target_valence and target_energy (energy replaces arousal).
|
| 129 |
+
The tool internally maps mood words to corresponding Spotify parameters. For example:
|
| 130 |
+
- "happy": target_valence ~ 0.9, target_energy ~ 0.8, seed_genre "pop"
|
| 131 |
+
- "sad": target_valence ~ 0.2, target_energy ~ 0.3, seed_genre "acoustic"
|
| 132 |
+
- "energetic": target_valence ~ 0.7, target_energy ~ 0.9, seed_genre "work-out"
|
| 133 |
+
- "chill": target_valence ~ 0.6, target_energy ~ 0.4, seed_genre "chill"
|
| 134 |
+
|
| 135 |
+
If 'local' is True, the tool uses the user's location and weather to adjust the mapping
|
| 136 |
+
(e.g., reducing energy on rainy days).
|
| 137 |
"""
|
| 138 |
weather_condition = None
|
| 139 |
if local:
|