ReverseMind / app.py
chinesemusk's picture
Update app.py
0b7c39a verified
import gradio as gr
import requests
# --- Lyrics Fetching Logic ---
def get_lyrics(song_name):
try:
url = f"https://api.lyrics.ovh/v1/{song_name.replace(' ', '%20')}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data.get("lyrics", "Lyrics not found.")
else:
return "Lyrics not found. Please check the song name."
except Exception as e:
return f"Error fetching lyrics: {str(e)}"
# Optional: Spotify Track Embed (only previews)
def get_spotify_embed(song_name):
query = song_name.replace(' ', '+')
return f"https://open.spotify.com/search/{query}"
# --- Gradio UI ---
def run_lyrics_agent(song):
lyrics = get_lyrics(song)
link = get_spotify_embed(song)
return lyrics, f"[Search on Spotify]({link})"
with gr.Blocks(css="body { background-color: #111827; color: #eee; }") as demo:
gr.Markdown("""
<style>body { background-color: #111827; color: #eee; }</style>
# 🎡 AI Lyrics Genie
Type a song title and get the full lyrics! ✨
_For now, this agent can also help you search the song on Spotify._
""")
with gr.Row():
song_input = gr.Textbox(label="🎀 Enter Song Name", placeholder="e.g., Bohemian Rhapsody")
search_btn = gr.Button("Get Lyrics 🎢")
lyrics_output = gr.Textbox(label="πŸ“„ Lyrics", lines=20)
spotify_link = gr.Markdown()
search_btn.click(fn=run_lyrics_agent, inputs=song_input, outputs=[lyrics_output, spotify_link])
# Launch for Hugging Face Spaces
if __name__ == "__main__":
demo.launch()