Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
def convert_suno_to_mp3(url: str):
|
| 4 |
"""
|
| 5 |
Convert a Suno song URL to the direct MP3 link.
|
| 6 |
-
Example:
|
| 7 |
-
https://suno.com/song/c0cdb3ad-f49d-4125-8e16-4d7dd7924a02?sh=...
|
| 8 |
-
->
|
| 9 |
-
https://cdn1.suno.ai/c0cdb3ad-f49d-4125-8e16-4d7dd7924a02.mp3
|
| 10 |
"""
|
| 11 |
-
import re
|
| 12 |
match = re.search(r'suno\.com/song/([a-f0-9\-]+)', url)
|
| 13 |
if not match:
|
| 14 |
return "Invalid Suno URL", None
|
| 15 |
song_id = match.group(1)
|
| 16 |
mp3_url = f"https://cdn1.suno.ai/{song_id}.mp3"
|
| 17 |
-
return mp3_url, mp3_url #
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
gr.Markdown("## Suno Song → Direct MP3 Converter")
|
|
@@ -24,11 +20,14 @@ with gr.Blocks() as demo:
|
|
| 24 |
mp3_output = gr.Textbox(label="MP3 URL")
|
| 25 |
download_btn = gr.File(label="Download MP3")
|
| 26 |
|
| 27 |
-
def
|
| 28 |
mp3_link, downloadable = convert_suno_to_mp3(url)
|
| 29 |
return mp3_link, downloadable
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
demo.launch()
|
| 34 |
|
|
|
|
| 1 |
import gradio as gr
|
| 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 |
"""
|
|
|
|
| 8 |
match = re.search(r'suno\.com/song/([a-f0-9\-]+)', url)
|
| 9 |
if not match:
|
| 10 |
return "Invalid Suno URL", None
|
| 11 |
song_id = match.group(1)
|
| 12 |
mp3_url = f"https://cdn1.suno.ai/{song_id}.mp3"
|
| 13 |
+
return mp3_url, mp3_url # display, downloadable link
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
gr.Markdown("## Suno Song → Direct MP3 Converter")
|
|
|
|
| 20 |
mp3_output = gr.Textbox(label="MP3 URL")
|
| 21 |
download_btn = gr.File(label="Download MP3")
|
| 22 |
|
| 23 |
+
def convert(url):
|
| 24 |
mp3_link, downloadable = convert_suno_to_mp3(url)
|
| 25 |
return mp3_link, downloadable
|
| 26 |
|
| 27 |
+
# bind the function to input changes
|
| 28 |
+
song_input.change(convert, inputs=song_input, outputs=[mp3_output, download_btn])
|
| 29 |
+
|
| 30 |
+
# 🚀 Add API name explicitly
|
| 31 |
+
demo.launch(api_name="convert")
|
| 32 |
|
|
|
|
| 33 |
|