haraberget commited on
Commit
fd06651
·
verified ·
1 Parent(s): 53e5819

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -101
app.py CHANGED
@@ -1,108 +1,34 @@
1
  import gradio as gr
2
 
3
- # Function to return the HTML iframe
4
- def show_website():
5
- html_code = """
6
- <!DOCTYPE html>
7
- <html lang="en">
8
- <head>
9
-
10
-
11
-
12
-
13
-
14
- <!DOCTYPE html>
15
- <html lang="en">
16
- <head>
17
- <meta charset="UTF-8">
18
- <title>Suno MP3 Converter</title>
19
- <style>
20
- body { font-family:sans-serif; background:#111; color:#eee; padding:2rem; }
21
- input, button { padding:0.5rem; margin:0.5rem 0; width:100%; }
22
- a { color:#0f0; display:block; margin-top:1rem; }
23
- </style>
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
- <meta charset="UTF-8">
47
- <title>Suno Embed</title>
48
- <style>
49
- body {
50
- font-family: sans-serif;
51
- background: #111;
52
- color: #eee;
53
- padding: 2rem;
54
- }
55
- iframe {
56
- border: none;
57
- display: block;
58
- margin-bottom: 1rem;
59
- }
60
- a {
61
- color: #0af;
62
- text-decoration: none;
63
- }
64
- a:hover {
65
- text-decoration: underline;
66
- }
67
- </style>
68
- </head>
69
-
70
-
71
-
72
- <body>
73
-
74
- <h1>Suno Song → Direct MP3</h1>
75
-
76
- <input id="songUrl" placeholder="Paste Suno song URL here" />
77
- <button id="convertBtn">Convert to MP3</button>
78
-
79
- <div id="result"></div>
80
-
81
- <script>
82
- document.getElementById("convertBtn").onclick = () => {
83
- const url = document.getElementById("songUrl").value.trim();
84
- const match = url.match(/suno\.com\/song\/([a-f0-9\-]+)/i);
85
- if(match){
86
- const uuid = match[1];
87
- const mp3Url = `https://cdn1.suno.ai/${uuid}.mp3`;
88
- document.getElementById("result").innerHTML = `
89
- <p>Direct MP3 URL:</p>
90
- <a href="${mp3Url}" download>Download MP3</a>
91
- <audio controls src="${mp3Url}"></audio>
92
- `;
93
- } else {
94
- document.getElementById("result").innerHTML = `<p style="color:red;">Invalid Suno URL!</p>`;
95
- }
96
- };
97
- </script>
98
-
99
- </html>
100
  """
101
- return html_code
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- # Create Gradio interface
104
  with gr.Blocks() as demo:
105
- gr.HTML("<h2>Website Viewer</h2>")
106
- website_viewer = gr.HTML(show_website)
 
 
 
 
 
 
 
 
 
 
107
 
108
  demo.launch()
 
 
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 # first is displayed, second is downloadable link
18
 
 
19
  with gr.Blocks() as demo:
20
+ gr.Markdown("## Suno Song → Direct MP3 Converter")
21
+
22
+ with gr.Row():
23
+ song_input = gr.Textbox(label="Enter Suno song URL", placeholder="https://suno.com/song/...")
24
+ mp3_output = gr.Textbox(label="MP3 URL")
25
+ download_btn = gr.File(label="Download MP3")
26
+
27
+ def update(url):
28
+ mp3_link, downloadable = convert_suno_to_mp3(url)
29
+ return mp3_link, downloadable
30
+
31
+ song_input.change(update, inputs=song_input, outputs=[mp3_output, download_btn])
32
 
33
  demo.launch()
34
+