Spaces:
Sleeping
Sleeping
import gradio as gr | |
import lyricsgenius | |
import re | |
# Initialize Genius API client | |
genius = lyricsgenius.Genius("YOUR_GENIUS_ACCESS_TOKEN") | |
def get_lyrics_from_link(link): | |
try: | |
# Extract song path from Genius link | |
song_path = re.search(r"genius\.com/([\w-]+)-lyrics$", link) | |
if song_path: | |
# Search song by song path | |
song = genius.search_song(song_path.group(1).replace("-", " ")) | |
if song: | |
return song.lyrics | |
else: | |
return "Song not found. Please check the link." | |
else: | |
return "Invalid link format. Please provide a correct Genius lyrics link." | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |
# Create Gradio interface | |
with gr.Blocks(theme="Hev832/niceandsimple") as demo: | |
gr.Markdown("## Get Lyrics from Genius Link") | |
link_input = gr.Textbox(label="Genius Link", | |
placeholder="Enter Genius lyrics link here...", | |
value="https://genius.com/Maimymayo-silly-billy-with-lyrics-hit-single-real-cover-lyrics") # Example link added | |
output = gr.Textbox(label="Lyrics", lines=15) | |
get_lyrics_button = gr.Button("Get Lyrics") | |
get_lyrics_button.click(get_lyrics_from_link, inputs=link_input, outputs=output) | |
demo.launch() | |