MichaelP719 commited on
Commit
c98695e
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files

First draft of similar song finder

Files changed (1) hide show
  1. app.py +24 -6
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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: