Spaces:
Sleeping
Sleeping
Update app.py
Browse files12 unmodified lines13141516171819202122232425262728293031323334353637383940414243444546474832 unmodified lines8182838485868712 unmodified lines@tooldef get_movies_by_mood(mood: str) -> str:"""Suggests up to 5 movies based on the user's mood using OMDB API.Args:mood: a current emotional state or feeling of a user (e.g., 'sad', 'happy', 'romantic')"""mood_keywords = {"happy": "comedy","sad": "drama","romantic": "romance","inspired": "biography","bored": "action","stressed": "family","excited": "adventure","lonely": "friendship"}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()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 "Couldn't find movies matching your mood. Try again!"@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = 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)max_steps=6,verbosity_level=1,grammar=None,12 unmodified lines131415161718192021222324252627282930313233343536373839404142434445464748495051525332 unmodified lines8687888990919212 unmodified lines@tooldef get_movies_by_mood(mood: str) -> str:"""Suggests up to 5 movies based on user's mood using OMDb API.Args:mood: Current emotional status or feeling of a user (e.g., 'sad', 'lonely', 'romantic')."""mood_keywords = {"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"]}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)return "Sorry, I couldn't find any matching movies for that mood right now."@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = CodeAgent(model=model,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