MySafeCode's picture
Update app.py
7333778 verified
raw
history blame contribute delete
960 Bytes
import gradio as gr
import re
def convert_url_to_mp3(url: str):
"""
Convert a Suno song URL to the direct MP3 link.
Returns a tuple: (displayed URL, downloadable URL)
"""
match = re.search(r'suno\.com/song/([a-f0-9\-]+)', url)
if not match:
return "Invalid Suno URL", None
song_id = match.group(1)
mp3_url = f"https://cdn1.suno.ai/{song_id}.mp3"
return mp3_url, mp3_url # first displayed, second downloadable
# Define the Gradio interface
demo = gr.Interface(
fn=convert_url_to_mp3, # Use the function name convert_url_to_mp3
inputs=gr.Textbox(label="Enter Suno song URL", placeholder="https://suno.com/song/..."),
outputs=[
gr.Textbox(label="MP3 URL"),
gr.File(label="Download MP3")
],
title="Suno → MP3 Converter",
description="Enter any Suno song URL to get a direct MP3 link."
)
# Launch the Space
if __name__ == "__main__":
demo.launch(share=True, debug=True)