Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,18 +2,32 @@ import gradio as gr
|
|
| 2 |
import re
|
| 3 |
|
| 4 |
def convert_suno_to_mp3(url: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
match = re.search(r'suno\.com/song/([a-f0-9\-]+)', url)
|
| 6 |
if not match:
|
| 7 |
return "Invalid Suno URL", None
|
|
|
|
| 8 |
song_id = match.group(1)
|
| 9 |
mp3_url = f"https://cdn1.suno.ai/{song_id}.mp3"
|
| 10 |
-
return mp3_url, mp3_url
|
| 11 |
|
|
|
|
| 12 |
demo = gr.Interface(
|
| 13 |
fn=convert_suno_to_mp3,
|
| 14 |
-
inputs=gr.Textbox(label="Enter Suno song URL"),
|
| 15 |
-
outputs=[
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import re
|
| 3 |
|
| 4 |
def convert_suno_to_mp3(url: str):
|
| 5 |
+
"""
|
| 6 |
+
Convert a Suno song URL to the direct MP3 link.
|
| 7 |
+
Returns a tuple: (displayed URL, downloadable URL)
|
| 8 |
+
"""
|
| 9 |
match = re.search(r'suno\.com/song/([a-f0-9\-]+)', url)
|
| 10 |
if not match:
|
| 11 |
return "Invalid Suno URL", None
|
| 12 |
+
|
| 13 |
song_id = match.group(1)
|
| 14 |
mp3_url = f"https://cdn1.suno.ai/{song_id}.mp3"
|
| 15 |
+
return mp3_url, mp3_url # first displayed, second downloadable
|
| 16 |
|
| 17 |
+
# Define the Gradio interface
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=convert_suno_to_mp3,
|
| 20 |
+
inputs=gr.Textbox(label="Enter Suno song URL", placeholder="https://suno.com/song/..."),
|
| 21 |
+
outputs=[
|
| 22 |
+
gr.Textbox(label="MP3 URL"),
|
| 23 |
+
gr.File(label="Download MP3")
|
| 24 |
+
],
|
| 25 |
+
title="Suno → MP3 Converter",
|
| 26 |
+
description="Enter any Suno song URL to get a direct MP3 link.",
|
| 27 |
+
api_name="convert" # ✅ this exposes /convert endpoint
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Launch the Space
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
demo.launch()
|
| 33 |
+
|