uncleMehrzad commited on
Commit
f3ff113
·
verified ·
1 Parent(s): 0b0edb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -76
app.py CHANGED
@@ -19,82 +19,7 @@ def find_the_song(arg1: str) -> str:
19
  arg1: a verse of a song or words that are refrencing a song.
20
  """
21
 
22
- try:
23
- search_term = f"site:genius.com OR site:azlyrics.com song lyrics \"{arg1}\"" #Focus on specific lyric sites
24
- search_tool = DuckDuckGoSearchTool()
25
- search_results = search_tool.run(search_term)
26
-
27
-
28
- if search_results:
29
- #Try extracting information from Genius or AZLyrics (prioritized)
30
- if "genius.com" in search_results.lower():
31
- try:
32
- url = re.search(r'(https?://[^\s]+)', search_results).group(0) # Get the genius URL
33
- response = requests.get(url)
34
- soup = BeautifulSoup(response.content, 'html.parser') #html parser
35
- song_title = soup.find("h1", class_="song_title").text.strip() if soup.find("h1", class_="song_title") else None #search song's name from specific h1 tag
36
- artist = soup.find("a", class_="artist_name").text.strip() if soup.find("a", class_="artist_name") else None #same but for artist name
37
- lyrics_div = soup.find("div", class_="lyrics") if soup.find("div", class_="lyrics") else soup.find("div", class_="Lyrics__Container") #finding lyrics tags (check them both if one is not available)
38
- if lyrics_div:
39
- lyrics = lyrics_div.get_text(separator="\n").strip()
40
- else:
41
- lyrics = None
42
-
43
- except Exception as e:
44
- return f"Error scraping Genius: {e}. Raw results: {search_results}"
45
- elif "azlyrics.com" in search_results.lower():
46
- try:
47
- url = re.search(r'(https?://[^\s]+)', search_results).group(0) # Get the azlyrics URL
48
- response = requests.get(url)
49
- soup = BeautifulSoup(response.content, 'html.parser')
50
- lyrics_div = soup.find("div", class_="ringtone") # Lyrics are inside a specific div
51
- if lyrics_div:
52
- lyrics = lyrics_div.find_next("div").get_text().strip() # Get the lyrics that are in the next div
53
- artist_element = soup.find('div', class_='lyricsh') # Find the tag of the lyrics
54
- artist = artist_element.find_next('b').text.split('lyrics')[0].strip() #parse the artist's name out
55
- song_title = soup.find('title').text.split(' - ')[0].strip() #same for name
56
-
57
-
58
-
59
- else:
60
- lyrics = None
61
- except Exception as e:
62
- return f"Error scraping AZLyrics: {e}. Raw results: {search_results}"
63
-
64
- else:
65
- return f"Could not find Genius or AZLyrics page, so couldn't extract lyrics. Raw results: {search_results}"
66
-
67
- #Fallback: Simple regex extraction of song and artist names
68
- if song_title is None or artist is None:
69
- title_match = re.search(r"Title:\s*(.*)", search_results, re.IGNORECASE)
70
- artist_match = re.search(r"Artist:\s*(.*)", search_results, re.IGNORECASE)
71
-
72
- song_title = title_match.group(1).strip() if title_match else None
73
- artist = artist_match.group(1).strip() if artist_match else None
74
-
75
- #Hardcoded URL example
76
- if song_title == 'TV' and artist == 'Billie Eilish':
77
- spotify_url = "https://open.spotify.com/track/3GYlZ7tbxLOxe6ewMNVTkw?autoplay=true"
78
- else: spotify_url = None
79
-
80
- # Construct the final answer
81
- if song_title and artist and lyrics and spotify_url:
82
- return f"song name: {song_title} , by {artist} . the spotify url is : {spotify_url} \nthe lyrics are : {lyrics}" # return the song + lyrics
83
-
84
-
85
- #Handle partial results - even if can't find the URL or Lyrics:
86
- if song_title and artist:
87
- spotify_message = f"\n(Could not reliably extract Spotify URL)" if spotify_url is None else ""
88
- lyrics_message = f"\n(Could not reliably extract Lyrics)" if lyrics is None else ""
89
- return f"Found song: {song_title} by {artist} . {spotify_message}{lyrics_message}. Raw results: {search_results}"
90
- return f"Could not extract full information, check the search results:\n {search_results}" #in case it fails return the search result
91
-
92
-
93
- else:
94
- return "Could not find any songs matching the verse."
95
-
96
- except Exception as e:
97
- return f"An error occurred: {e}"
98
 
99
  @tool
100
  def get_current_time_in_timezone(timezone: str) -> str:
 
19
  arg1: a verse of a song or words that are refrencing a song.
20
  """
21
 
22
+ return "ffff"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  @tool
25
  def get_current_time_in_timezone(timezone: str) -> str: