Spaces:
Runtime error
Runtime error
Update app.py
Browse filesFirst draft of similar song finder
app.py
CHANGED
|
@@ -7,16 +7,34 @@ 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 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
+
ddg = DuckDuckGoSearchTool()
|
| 12 |
+
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
| 15 |
+
def find_similar_songs(query: str)-> str:
|
| 16 |
+
"""Given a song title or artist name, search the web for "songs like [query]" or "if you like [query]" and return the top 5 links with titles and snippets
|
|
|
|
| 17 |
Args:
|
| 18 |
+
query: the song or artist that the user would like to find songs or artists similar to
|
|
|
|
| 19 |
"""
|
| 20 |
+
saerch_terms = f"songs like {query} or if you like {query}."
|
| 21 |
+
results = ddg.run(search_terms, max_results=6)
|
| 22 |
+
|
| 23 |
+
if not results:
|
| 24 |
+
return f"No results found for '{query}'."
|
| 25 |
+
|
| 26 |
+
md = f"### Similar songs to **{query}**\n\n"
|
| 27 |
+
for item in results[:5]:
|
| 28 |
+
# DuckDuckGoSearchTool typically gives fields like 'title', 'href', 'body'
|
| 29 |
+
title = item.get("title") or item.get("heading", "Untitled")
|
| 30 |
+
link = item.get("href") or item.get("link", "")
|
| 31 |
+
snippet = item.get("body") or item.get("snippet", "")
|
| 32 |
+
md += f"- **[{title}]({link})**\n"
|
| 33 |
+
if snippet:
|
| 34 |
+
md += f" > {snippet.strip()}\n"
|
| 35 |
+
md += "\n"
|
| 36 |
+
|
| 37 |
+
return md.strip()
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|