haraberget's picture
Update app.py
53e5819 verified
raw
history blame
1.82 kB
import gradio as gr
# Function to return the HTML iframe
def show_website():
html_code = """
<!DOCTYPE html>
<html lang="en">
<head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Suno MP3 Converter</title>
<style>
body { font-family:sans-serif; background:#111; color:#eee; padding:2rem; }
input, button { padding:0.5rem; margin:0.5rem 0; width:100%; }
a { color:#0f0; display:block; margin-top:1rem; }
</style>
<meta charset="UTF-8">
<title>Suno Embed</title>
<style>
body {
font-family: sans-serif;
background: #111;
color: #eee;
padding: 2rem;
}
iframe {
border: none;
display: block;
margin-bottom: 1rem;
}
a {
color: #0af;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Suno Song → Direct MP3</h1>
<input id="songUrl" placeholder="Paste Suno song URL here" />
<button id="convertBtn">Convert to MP3</button>
<div id="result"></div>
<script>
document.getElementById("convertBtn").onclick = () => {
const url = document.getElementById("songUrl").value.trim();
const match = url.match(/suno\.com\/song\/([a-f0-9\-]+)/i);
if(match){
const uuid = match[1];
const mp3Url = `https://cdn1.suno.ai/${uuid}.mp3`;
document.getElementById("result").innerHTML = `
<p>Direct MP3 URL:</p>
<a href="${mp3Url}" download>Download MP3</a>
<audio controls src="${mp3Url}"></audio>
`;
} else {
document.getElementById("result").innerHTML = `<p style="color:red;">Invalid Suno URL!</p>`;
}
};
</script>
</html>
"""
return html_code
# Create Gradio interface
with gr.Blocks() as demo:
gr.HTML("<h2>Website Viewer</h2>")
website_viewer = gr.HTML(show_website)
demo.launch()