Spaces:
Sleeping
Sleeping
Update app.py
Browse files12 unmodified lines1314151616171718191920212222232425262728292324252627282930313232333334353637383940414243444546474835363738394041424349504551525332 unmodified lines868788848990919212 unmodified lines
@tooldef get_movies_by_mood(mood: str) -> str: """ """Suggests up to 5 movies based on the user's mood using OMDB API. Suggests up to 5 movies based on user's mood using OMDb API.
Args: mood: a current emotional state or feeling of a user (e.g., 'sad', 'happy', 'romantic') mood: Current emotional status or feeling of a user (e.g., 'sad', 'lonely', 'romantic'). """ mood_keywords = { "happy": "comedy", "sad": "drama", "romantic": "romance", "inspired": "biography", "bored": "action", "stressed": "family", "excited": "adventure", "lonely": "friendship" "happy": ["comedy", "feel good"], "sad": ["drama", "emotional"], "romantic": ["romance", "love"], "inspired": ["biography", "true story"], "bored": ["action", "thriller"], "stressed": ["family", "light"], "excited": ["adventure", "epic"], "lonely": ["friendship", "self discovery"] }
keyword = next((v for k, v in mood_keywords.items() if k in mood.lower()), "drama") search = requests.get(f"http://www.omdbapi.com/?s={keyword}&apikey={OMDB_API_KEY}&type=movie").json() fallback_keywords = mood_keywords.get( next((k for k in mood_keywords if k in mood.lower()), "sad"), ["drama"] )
for keyword in fallback_keywords: res = requests.get(f"http://www.omdbapi.com/?s={keyword}&apikey={OMDB_API_KEY}&type=movie").json() if "Search" in res: movies = [] for movie in res["Search"][:5]: info = requests.get(f"http://www.omdbapi.com/?i={movie['imdbID']}&apikey={OMDB_API_KEY}").json() title = info.get("Title", "Unknown") year = info.get("Year", "N/A") plot = info.get("Plot", "No plot available.") movies.append(f"{title} ({year}): {plot}") return "\n\n".join(movies)
if "Search" in search: movies = [] for movie in search["Search"][:5]: info = requests.get(f"http://www.omdbapi.com/?i={movie['imdbID']}&apikey={OMDB_API_KEY}").json() title = info.get("Title", "Unknown") year = info.get("Year", "N/A") plot = info.get("Plot", "No plot available.") movies.append(f"{title} ({year}): {plot}") return "\n\n".join(movies) return "Sorry, I couldn't find any matching movies for that mood right now."
return "Couldn't find movies matching your mood. Try again!" @tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified lines agent = CodeAgent( model=model, tools=[final_answer, get_current_time_in_timezone, get_movies_by_mood, DuckDuckGoSearchTool], ## add your tools here (don't remove final answer) tools=[final_answer, get_current_time_in_timezone, get_movies_by_mood], ## add your tools here (don't remove final answer) max_steps=6, verbosity_level=1, grammar=None,app.py+29-24