Spaces:
Sleeping
Sleeping
EconLab AI
commited on
Commit
·
bc05d79
1
Parent(s):
9c7965f
gradioaudio
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import scipy.io.wavfile
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# Sicherstellen, dass der 'static'-Ordner existiert
|
| 7 |
os.makedirs('static', exist_ok=True)
|
|
@@ -36,13 +37,15 @@ def generate_music(prompt, duration, sampling_rate):
|
|
| 36 |
# Benutzerdefiniertes CSS
|
| 37 |
custom_css = """
|
| 38 |
body {
|
| 39 |
-
background-color: #
|
| 40 |
-
color: #
|
| 41 |
font-family: 'Arial', sans-serif;
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
button {
|
| 45 |
-
background-color: #
|
| 46 |
color: white;
|
| 47 |
font-weight: bold;
|
| 48 |
border-radius: 5px;
|
|
@@ -53,7 +56,7 @@ button {
|
|
| 53 |
}
|
| 54 |
|
| 55 |
button:hover {
|
| 56 |
-
background-color: #
|
| 57 |
}
|
| 58 |
|
| 59 |
input[type="text"], textarea {
|
|
@@ -67,7 +70,7 @@ input[type="text"], textarea {
|
|
| 67 |
}
|
| 68 |
|
| 69 |
.slider {
|
| 70 |
-
accent-color: #
|
| 71 |
}
|
| 72 |
|
| 73 |
audio {
|
|
@@ -80,37 +83,44 @@ audio {
|
|
| 80 |
# Gradio-Interface erstellen
|
| 81 |
with gr.Blocks(css=custom_css) as demo:
|
| 82 |
gr.Markdown(
|
| 83 |
-
"<h1 style='text-align: center;'>🎶
|
| 84 |
elem_id="title"
|
| 85 |
)
|
| 86 |
gr.Markdown(
|
| 87 |
-
"<p style='text-align: center;'>Generate
|
| 88 |
)
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Column(scale=2):
|
| 92 |
prompt = gr.Textbox(
|
| 93 |
label="Prompt",
|
| 94 |
-
placeholder="Describe the music you want to generate"
|
| 95 |
-
elem_id="prompt-box"
|
| 96 |
)
|
| 97 |
duration = gr.Slider(
|
| 98 |
label="Duration in Seconds",
|
| 99 |
minimum=1,
|
| 100 |
maximum=60,
|
| 101 |
-
value=30
|
| 102 |
-
elem_id="duration-slider"
|
| 103 |
)
|
| 104 |
sampling_rate = gr.Slider(
|
| 105 |
label="Sampling Rate (kHz)",
|
| 106 |
minimum=16,
|
| 107 |
maximum=48,
|
| 108 |
-
value=24
|
| 109 |
-
elem_id="sampling-slider"
|
| 110 |
)
|
| 111 |
-
generate_button = gr.Button("Generate"
|
| 112 |
with gr.Column(scale=3):
|
| 113 |
-
output = gr.Audio(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Ereignisbindung
|
| 116 |
generate_button.click(
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import scipy.io.wavfile
|
| 4 |
import os
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
# Sicherstellen, dass der 'static'-Ordner existiert
|
| 8 |
os.makedirs('static', exist_ok=True)
|
|
|
|
| 37 |
# Benutzerdefiniertes CSS
|
| 38 |
custom_css = """
|
| 39 |
body {
|
| 40 |
+
background-color: #121212;
|
| 41 |
+
color: #e0e0e0;
|
| 42 |
font-family: 'Arial', sans-serif;
|
| 43 |
+
margin: 0;
|
| 44 |
+
padding: 0;
|
| 45 |
}
|
| 46 |
|
| 47 |
button {
|
| 48 |
+
background-color: #1db954;
|
| 49 |
color: white;
|
| 50 |
font-weight: bold;
|
| 51 |
border-radius: 5px;
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
button:hover {
|
| 59 |
+
background-color: #1ed760;
|
| 60 |
}
|
| 61 |
|
| 62 |
input[type="text"], textarea {
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
.slider {
|
| 73 |
+
accent-color: #1db954;
|
| 74 |
}
|
| 75 |
|
| 76 |
audio {
|
|
|
|
| 83 |
# Gradio-Interface erstellen
|
| 84 |
with gr.Blocks(css=custom_css) as demo:
|
| 85 |
gr.Markdown(
|
| 86 |
+
"<h1 style='text-align: center;'>🎶 Modern Audio Generator</h1>",
|
| 87 |
elem_id="title"
|
| 88 |
)
|
| 89 |
gr.Markdown(
|
| 90 |
+
"<p style='text-align: center;'>Generate studio-quality music from your prompts with advanced options.</p>"
|
| 91 |
)
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
with gr.Column(scale=2):
|
| 95 |
prompt = gr.Textbox(
|
| 96 |
label="Prompt",
|
| 97 |
+
placeholder="Describe the music you want to generate"
|
|
|
|
| 98 |
)
|
| 99 |
duration = gr.Slider(
|
| 100 |
label="Duration in Seconds",
|
| 101 |
minimum=1,
|
| 102 |
maximum=60,
|
| 103 |
+
value=30
|
|
|
|
| 104 |
)
|
| 105 |
sampling_rate = gr.Slider(
|
| 106 |
label="Sampling Rate (kHz)",
|
| 107 |
minimum=16,
|
| 108 |
maximum=48,
|
| 109 |
+
value=24
|
|
|
|
| 110 |
)
|
| 111 |
+
generate_button = gr.Button("Generate")
|
| 112 |
with gr.Column(scale=3):
|
| 113 |
+
output = gr.Audio(
|
| 114 |
+
label="Generated Music",
|
| 115 |
+
type="filepath",
|
| 116 |
+
autoplay=True,
|
| 117 |
+
show_download_button=True,
|
| 118 |
+
format="wav",
|
| 119 |
+
waveform_options={
|
| 120 |
+
"waveform_color": "#1db954",
|
| 121 |
+
"waveform_progress_color": "#e0e0e0"
|
| 122 |
+
}
|
| 123 |
+
)
|
| 124 |
|
| 125 |
# Ereignisbindung
|
| 126 |
generate_button.click(
|