Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,10 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 13 |
@tool
|
| 14 |
|
| 15 |
-
def fetch_movie_from_omdb(genre: str) -> dict:
|
| 16 |
"""
|
| 17 |
Fetch a movie recommendation from the OMDb API based on a given genre.
|
| 18 |
|
|
@@ -44,7 +45,8 @@ def fetch_movie_from_omdb(genre: str) -> dict:
|
|
| 44 |
"year": best_movie["Year"],
|
| 45 |
"genre": genre,
|
| 46 |
"imdb_id": best_movie["imdbID"]
|
| 47 |
-
}
|
|
|
|
| 48 |
@tool
|
| 49 |
|
| 50 |
def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -> dict:
|
|
@@ -86,33 +88,26 @@ def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -
|
|
| 86 |
"thunderstorm": "Thriller"
|
| 87 |
}
|
| 88 |
|
| 89 |
-
|
| 90 |
recommended_genres = genre_mapping.get(mood, ["Drama"])
|
| 91 |
for key in weather_mapping:
|
| 92 |
if key in weather_condition:
|
| 93 |
recommended_genres.append(weather_mapping[key])
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
# Fetch top movies from IMDb by genre
|
| 98 |
-
genre_movies = []
|
| 99 |
-
for genre in recommended_genres:
|
| 100 |
-
try:
|
| 101 |
-
top_movies = ia.get_top50_movies_by_genre(genre)
|
| 102 |
-
genre_movies.extend(top_movies)
|
| 103 |
-
except Exception:
|
| 104 |
-
continue # Skip if genre is unavailable
|
| 105 |
-
|
| 106 |
-
if not genre_movies:
|
| 107 |
return {"error": "No suitable movie found."}
|
| 108 |
|
| 109 |
-
best_movie =
|
| 110 |
-
|
| 111 |
return {
|
| 112 |
"title": best_movie.get("title", "Unknown"),
|
| 113 |
"genre": recommended_genres,
|
| 114 |
-
"description": best_movie.get("
|
| 115 |
-
"
|
| 116 |
}
|
| 117 |
|
| 118 |
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
+
'''
|
| 14 |
@tool
|
| 15 |
|
| 16 |
+
#def fetch_movie_from_omdb(genre: str) -> dict:
|
| 17 |
"""
|
| 18 |
Fetch a movie recommendation from the OMDb API based on a given genre.
|
| 19 |
|
|
|
|
| 45 |
"year": best_movie["Year"],
|
| 46 |
"genre": genre,
|
| 47 |
"imdb_id": best_movie["imdbID"]
|
| 48 |
+
}
|
| 49 |
+
'''
|
| 50 |
@tool
|
| 51 |
|
| 52 |
def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -> dict:
|
|
|
|
| 88 |
"thunderstorm": "Thriller"
|
| 89 |
}
|
| 90 |
|
| 91 |
+
# Determine recommended genre
|
| 92 |
recommended_genres = genre_mapping.get(mood, ["Drama"])
|
| 93 |
for key in weather_mapping:
|
| 94 |
if key in weather_condition:
|
| 95 |
recommended_genres.append(weather_mapping[key])
|
| 96 |
|
| 97 |
+
# Search for a movie recommendation using DuckDuckGo
|
| 98 |
+
search_query = f"best {recommended_genres[0]} movies"
|
| 99 |
+
search_tool = DuckDuckGoSearchTool()
|
| 100 |
+
results = search_tool.search(search_query)
|
| 101 |
|
| 102 |
+
if not results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
return {"error": "No suitable movie found."}
|
| 104 |
|
| 105 |
+
best_movie = results[0]
|
|
|
|
| 106 |
return {
|
| 107 |
"title": best_movie.get("title", "Unknown"),
|
| 108 |
"genre": recommended_genres,
|
| 109 |
+
"description": best_movie.get("snippet", "No description available."),
|
| 110 |
+
"link": best_movie.get("link", "No link available")
|
| 111 |
}
|
| 112 |
|
| 113 |
|