EconLab AI commited on
Commit
c9d18d9
·
1 Parent(s): bc05d79

Updated layout and design for modern UI

Browse files
Files changed (1) hide show
  1. app.py +63 -48
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
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)
@@ -15,40 +14,51 @@ synthesizer = pipeline(
15
  )
16
 
17
  # Funktion zur Musikgenerierung
18
- def generate_music(prompt, duration, sampling_rate):
19
  try:
20
- # Musik generieren
21
- music = synthesizer(
22
- prompt,
23
- forward_params={"do_sample": True, "max_new_tokens": duration * sampling_rate}
24
- )
25
- # Ausgabe-Pfad definieren
26
  output_path = "static/generated_music.wav"
27
- # Musikdatei speichern
28
  scipy.io.wavfile.write(
29
  output_path,
30
  rate=music["sampling_rate"],
31
  data=music["audio"]
32
  )
33
- return output_path # Pfad zur generierten Musikdatei zurückgeben
34
  except Exception as e:
35
- return str(e) # Fehlernachricht zurückgeben
36
 
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;
52
  padding: 10px 20px;
53
  border: none;
54
  cursor: pointer;
@@ -56,21 +66,20 @@ button {
56
  }
57
 
58
  button:hover {
59
- background-color: #1ed760;
 
 
 
 
60
  }
61
 
62
- input[type="text"], textarea {
63
- background-color: #2a2a3d;
64
  color: white;
65
  border: 1px solid #444;
66
  padding: 10px;
67
  border-radius: 5px;
68
  font-size: 14px;
69
- width: 100%;
70
- }
71
-
72
- .slider {
73
- accent-color: #1db954;
74
  }
75
 
76
  audio {
@@ -82,53 +91,59 @@ audio {
82
 
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(
127
  fn=generate_music,
128
- inputs=[prompt, duration, sampling_rate],
129
  outputs=output
130
  )
131
 
 
 
 
 
 
 
132
  # Anwendung starten
133
  if __name__ == "__main__":
134
  demo.launch()
 
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)
 
14
  )
15
 
16
  # Funktion zur Musikgenerierung
17
+ def generate_music(prompt, duration, diffusion_steps, cfg_scale):
18
  try:
19
+ # Placeholder für generierte Musik
20
+ # Da MusicGen keine Diffusion Steps und CFG Scale unterstützt, sind diese Parameter hier symbolisch.
21
+ music = synthesizer(prompt, forward_params={"do_sample": True})
22
+
23
+ # Datei speichern
 
24
  output_path = "static/generated_music.wav"
 
25
  scipy.io.wavfile.write(
26
  output_path,
27
  rate=music["sampling_rate"],
28
  data=music["audio"]
29
  )
30
+ return output_path
31
  except Exception as e:
32
+ return f"Error: {str(e)}"
33
 
34
  # Benutzerdefiniertes CSS
35
  custom_css = """
36
  body {
37
  background-color: #121212;
38
+ color: #ffffff;
39
  font-family: 'Arial', sans-serif;
40
  margin: 0;
41
  padding: 0;
42
  }
43
 
44
+ #title {
45
+ text-align: center;
46
+ font-size: 24px;
47
+ font-weight: bold;
48
+ margin-bottom: 10px;
49
+ }
50
+
51
+ #description {
52
+ text-align: center;
53
+ font-size: 16px;
54
+ margin-bottom: 30px;
55
+ }
56
+
57
  button {
58
+ background-color: #ff5722;
59
  color: white;
60
  font-weight: bold;
61
+ border-radius: 8px;
62
  padding: 10px 20px;
63
  border: none;
64
  cursor: pointer;
 
66
  }
67
 
68
  button:hover {
69
+ background-color: #ff784e;
70
+ }
71
+
72
+ .slider {
73
+ accent-color: #ff5722;
74
  }
75
 
76
+ textarea, input[type="text"] {
77
+ background-color: #1e1e2f;
78
  color: white;
79
  border: 1px solid #444;
80
  padding: 10px;
81
  border-radius: 5px;
82
  font-size: 14px;
 
 
 
 
 
83
  }
84
 
85
  audio {
 
91
 
92
  # Gradio-Interface erstellen
93
  with gr.Blocks(css=custom_css) as demo:
94
+ gr.Markdown("<h1 id='title'>Stable Audio Generator</h1>")
95
+ gr.Markdown("<p id='description'>Generate variable-length stereo audio at 44.1kHz from text prompts using Stable Audio Open 1.0.</p>")
96
+
 
 
 
 
 
97
  with gr.Row():
98
  with gr.Column(scale=2):
99
  prompt = gr.Textbox(
100
  label="Prompt",
101
+ placeholder="Describe your music (e.g., 'Relaxing piano music')."
102
  )
103
  duration = gr.Slider(
104
  label="Duration in Seconds",
105
+ minimum=10,
106
  maximum=60,
107
+ step=1,
108
  value=30
109
  )
110
+ diffusion_steps = gr.Slider(
111
+ label="Number of Diffusion Steps",
112
+ minimum=50,
113
+ maximum=200,
114
+ step=10,
115
+ value=150
116
  )
117
+ cfg_scale = gr.Slider(
118
+ label="CFG Scale",
119
+ minimum=1,
120
+ maximum=20,
121
+ step=1,
122
+ value=10
123
+ )
124
+ generate_button = gr.Button("Submit")
125
+ with gr.Column(scale=1):
126
  output = gr.Audio(
127
  label="Generated Music",
128
  type="filepath",
129
+ autoplay=True
 
 
 
 
 
 
130
  )
131
 
132
+ with gr.Row():
133
+ clear_button = gr.Button("Clear")
134
+
135
  generate_button.click(
136
  fn=generate_music,
137
+ inputs=[prompt, duration, diffusion_steps, cfg_scale],
138
  outputs=output
139
  )
140
 
141
+ clear_button.click(
142
+ fn=lambda: None,
143
+ inputs=None,
144
+ outputs=[prompt, output]
145
+ )
146
+
147
  # Anwendung starten
148
  if __name__ == "__main__":
149
  demo.launch()