Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,36 +13,41 @@ OMDB_API_KEY = "OMDB_API_KEY"
|
|
| 13 |
|
| 14 |
@tool
|
| 15 |
def get_movies_by_mood(mood: str) -> str:
|
| 16 |
-
"""
|
| 17 |
-
|
|
|
|
| 18 |
Args:
|
| 19 |
-
mood:
|
| 20 |
"""
|
| 21 |
mood_keywords = {
|
| 22 |
-
"happy": "comedy",
|
| 23 |
-
"sad": "drama",
|
| 24 |
-
"romantic": "romance",
|
| 25 |
-
"inspired": "biography",
|
| 26 |
-
"bored": "action",
|
| 27 |
-
"stressed": "family",
|
| 28 |
-
"excited": "adventure",
|
| 29 |
-
"lonely": "friendship"
|
| 30 |
}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
movies = []
|
| 37 |
-
for movie in search["Search"][:5]:
|
| 38 |
-
info = requests.get(f"http://www.omdbapi.com/?i={movie['imdbID']}&apikey={OMDB_API_KEY}").json()
|
| 39 |
-
title = info.get("Title", "Unknown")
|
| 40 |
-
year = info.get("Year", "N/A")
|
| 41 |
-
plot = info.get("Plot", "No plot available.")
|
| 42 |
-
movies.append(f"{title} ({year}): {plot}")
|
| 43 |
-
return "\n\n".join(movies)
|
| 44 |
|
| 45 |
-
return "Couldn't find movies matching your mood. Try again!"
|
| 46 |
|
| 47 |
@tool
|
| 48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -81,7 +86,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 81 |
|
| 82 |
agent = CodeAgent(
|
| 83 |
model=model,
|
| 84 |
-
tools=[final_answer, get_current_time_in_timezone, get_movies_by_mood
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|
|
|
|
| 13 |
|
| 14 |
@tool
|
| 15 |
def get_movies_by_mood(mood: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Suggests up to 5 movies based on user's mood using OMDb API.
|
| 18 |
+
|
| 19 |
Args:
|
| 20 |
+
mood: Current emotional status or feeling of a user (e.g., 'sad', 'lonely', 'romantic').
|
| 21 |
"""
|
| 22 |
mood_keywords = {
|
| 23 |
+
"happy": ["comedy", "feel good"],
|
| 24 |
+
"sad": ["drama", "emotional"],
|
| 25 |
+
"romantic": ["romance", "love"],
|
| 26 |
+
"inspired": ["biography", "true story"],
|
| 27 |
+
"bored": ["action", "thriller"],
|
| 28 |
+
"stressed": ["family", "light"],
|
| 29 |
+
"excited": ["adventure", "epic"],
|
| 30 |
+
"lonely": ["friendship", "self discovery"]
|
| 31 |
}
|
| 32 |
|
| 33 |
+
fallback_keywords = mood_keywords.get(
|
| 34 |
+
next((k for k in mood_keywords if k in mood.lower()), "sad"), ["drama"]
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
for keyword in fallback_keywords:
|
| 38 |
+
res = requests.get(f"http://www.omdbapi.com/?s={keyword}&apikey={OMDB_API_KEY}&type=movie").json()
|
| 39 |
+
if "Search" in res:
|
| 40 |
+
movies = []
|
| 41 |
+
for movie in res["Search"][:5]:
|
| 42 |
+
info = requests.get(f"http://www.omdbapi.com/?i={movie['imdbID']}&apikey={OMDB_API_KEY}").json()
|
| 43 |
+
title = info.get("Title", "Unknown")
|
| 44 |
+
year = info.get("Year", "N/A")
|
| 45 |
+
plot = info.get("Plot", "No plot available.")
|
| 46 |
+
movies.append(f"{title} ({year}): {plot}")
|
| 47 |
+
return "\n\n".join(movies)
|
| 48 |
|
| 49 |
+
return "Sorry, I couldn't find any matching movies for that mood right now."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
|
|
|
| 51 |
|
| 52 |
@tool
|
| 53 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 86 |
|
| 87 |
agent = CodeAgent(
|
| 88 |
model=model,
|
| 89 |
+
tools=[final_answer, get_current_time_in_timezone, get_movies_by_mood], ## add your tools here (don't remove final answer)
|
| 90 |
max_steps=6,
|
| 91 |
verbosity_level=1,
|
| 92 |
grammar=None,
|