Spaces:
Sleeping
Sleeping
EconLab AI commited on
Commit ·
9c7965f
1
Parent(s): bd44176
css
Browse files
app.py
CHANGED
|
@@ -14,10 +14,13 @@ synthesizer = pipeline(
|
|
| 14 |
)
|
| 15 |
|
| 16 |
# Funktion zur Musikgenerierung
|
| 17 |
-
def generate_music(
|
| 18 |
try:
|
| 19 |
# Musik generieren
|
| 20 |
-
music = synthesizer(
|
|
|
|
|
|
|
|
|
|
| 21 |
# Ausgabe-Pfad definieren
|
| 22 |
output_path = "static/generated_music.wav"
|
| 23 |
# Musikdatei speichern
|
|
@@ -30,34 +33,92 @@ def generate_music(description):
|
|
| 30 |
except Exception as e:
|
| 31 |
return str(e) # Fehlernachricht zurückgeben
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Gradio-Interface erstellen
|
| 34 |
-
with gr.Blocks() as demo:
|
| 35 |
-
gr.Markdown(
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
-
with gr.Column(scale=3):
|
| 40 |
-
description = gr.Textbox(
|
| 41 |
-
label="Musikbeschreibung",
|
| 42 |
-
placeholder="Z.B. Ein fröhliches Lied mit Gitarren.",
|
| 43 |
-
lines=3
|
| 44 |
-
)
|
| 45 |
-
generate_button = gr.Button("🎼 Generieren")
|
| 46 |
with gr.Column(scale=2):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# Ereignisbindung
|
| 58 |
-
generate_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Anwendung starten
|
| 61 |
if __name__ == "__main__":
|
| 62 |
demo.launch()
|
| 63 |
-
# ddd
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
# Funktion zur Musikgenerierung
|
| 17 |
+
def generate_music(prompt, duration, sampling_rate):
|
| 18 |
try:
|
| 19 |
# Musik generieren
|
| 20 |
+
music = synthesizer(
|
| 21 |
+
prompt,
|
| 22 |
+
forward_params={"do_sample": True, "max_new_tokens": duration * sampling_rate}
|
| 23 |
+
)
|
| 24 |
# Ausgabe-Pfad definieren
|
| 25 |
output_path = "static/generated_music.wav"
|
| 26 |
# Musikdatei speichern
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return str(e) # Fehlernachricht zurückgeben
|
| 35 |
|
| 36 |
+
# Benutzerdefiniertes CSS
|
| 37 |
+
custom_css = """
|
| 38 |
+
body {
|
| 39 |
+
background-color: #1e1e2f;
|
| 40 |
+
color: #ffffff;
|
| 41 |
+
font-family: 'Arial', sans-serif;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
button {
|
| 45 |
+
background-color: #ff5722;
|
| 46 |
+
color: white;
|
| 47 |
+
font-weight: bold;
|
| 48 |
+
border-radius: 5px;
|
| 49 |
+
padding: 10px 20px;
|
| 50 |
+
border: none;
|
| 51 |
+
cursor: pointer;
|
| 52 |
+
font-size: 16px;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
button:hover {
|
| 56 |
+
background-color: #ff784e;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
input[type="text"], textarea {
|
| 60 |
+
background-color: #2a2a3d;
|
| 61 |
+
color: white;
|
| 62 |
+
border: 1px solid #444;
|
| 63 |
+
padding: 10px;
|
| 64 |
+
border-radius: 5px;
|
| 65 |
+
font-size: 14px;
|
| 66 |
+
width: 100%;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.slider {
|
| 70 |
+
accent-color: #ff5722;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
audio {
|
| 74 |
+
border: 2px solid #444;
|
| 75 |
+
border-radius: 5px;
|
| 76 |
+
margin-top: 10px;
|
| 77 |
+
}
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
# Gradio-Interface erstellen
|
| 81 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 82 |
+
gr.Markdown(
|
| 83 |
+
"<h1 style='text-align: center;'>🎶 Stable Audio Generator</h1>",
|
| 84 |
+
elem_id="title"
|
| 85 |
+
)
|
| 86 |
+
gr.Markdown(
|
| 87 |
+
"<p style='text-align: center;'>Generate high-quality music from your text prompts.</p>"
|
| 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", elem_id="generate-button")
|
| 112 |
+
with gr.Column(scale=3):
|
| 113 |
+
output = gr.Audio(label="Generated Music", type="filepath", autoplay=True)
|
| 114 |
|
| 115 |
# Ereignisbindung
|
| 116 |
+
generate_button.click(
|
| 117 |
+
fn=generate_music,
|
| 118 |
+
inputs=[prompt, duration, sampling_rate],
|
| 119 |
+
outputs=output
|
| 120 |
+
)
|
| 121 |
|
| 122 |
# Anwendung starten
|
| 123 |
if __name__ == "__main__":
|
| 124 |
demo.launch()
|
|
|