Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,36 +3,42 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
-
import os
|
| 7 |
-
from youtube_transcript_api import YouTubeTranscriptApi
|
| 8 |
-
import re
|
| 9 |
from tools.final_answer import FinalAnswerTool
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
|
|
|
|
|
|
|
| 15 |
@tool
|
| 16 |
-
def
|
| 17 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return match.grou(1)
|
| 34 |
-
else:
|
| 35 |
-
raise ValueError("Invalid YouTube URL.")
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
|
| 12 |
+
OMDB_API_KEY = "a08b4599"
|
| 13 |
+
|
| 14 |
@tool
|
| 15 |
+
def get_movies_by_mood(mood: str) -> str:
|
| 16 |
+
"""Suggests up to 5 movies based on the user's mood using OMDb API."""
|
| 17 |
+
mood_keywords = {
|
| 18 |
+
"happy": "comedy",
|
| 19 |
+
"sad": "drama",
|
| 20 |
+
"romantic": "romance",
|
| 21 |
+
"inspired": "biography",
|
| 22 |
+
"bored": "action",
|
| 23 |
+
"stressed": "family",
|
| 24 |
+
"excited": "adventure",
|
| 25 |
+
"lonely": "friendship"
|
| 26 |
+
}
|
| 27 |
|
| 28 |
+
keyword = next((v for k, v in mood_keywords.items() if k in mood.lower()), "drama")
|
| 29 |
+
search = requests.get(f"http://www.omdbapi.com/?s={keyword}&apikey={OMDB_API_KEY}&type=movie").json()
|
| 30 |
+
|
| 31 |
+
if "Search" in search:
|
| 32 |
+
movies = []
|
| 33 |
+
for movie in search["Search"][:5]:
|
| 34 |
+
info = requests.get(f"http://www.omdbapi.com/?i={movie['imdbID']}&apikey={OMDB_API_KEY}").json()
|
| 35 |
+
title = info.get("Title", "Unknown")
|
| 36 |
+
year = info.get("Year", "N/A")
|
| 37 |
+
plot = info.get("Plot", "No plot available.")
|
| 38 |
+
movies.append(f"{title} ({year}): {plot}")
|
| 39 |
+
return "\n\n".join(movies)
|
| 40 |
+
|
| 41 |
+
return "Couldn't find movies matching your mood. Try again!"
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|