Spaces:
Sleeping
Sleeping
| 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() | |