OpenSound commited on
Commit
5d104f9
1 Parent(s): 73dd36c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -32
app.py CHANGED
@@ -83,35 +83,68 @@ def generate_audio(text, length,
83
  return params['autoencoder']['sr'], pred
84
 
85
 
86
- # Gradio Interface
87
- def gradio_interface():
88
- # Input components
89
- text_input = gr.Textbox(label="Text Prompt", value="the sound of dog barking")
90
- length_input = gr.Slider(minimum=1, maximum=10, step=1, value=10, label="Audio Length (in seconds)")
91
-
92
- # Advanced settings
93
- guidance_scale_input = gr.Slider(minimum=1.0, maximum=10, step=0.1, value=5, label="Guidance Scale")
94
- guidance_rescale_input = gr.Slider(minimum=0.0, maximum=1, step=0.05, value=0.75, label="Guidance Rescale")
95
- ddim_steps_input = gr.Slider(minimum=25, maximum=200, step=5, value=100, label="DDIM Steps")
96
- eta_input = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1, label="Eta")
97
- random_seed_input = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0,)
98
-
99
- randomize_seed = gr.Checkbox(label="Randomize seed", value=False)
100
-
101
- # Output component
102
- output_audio = gr.Audio(label="Converted Audio", type="numpy")
103
-
104
- # Interface
105
- gr.Interface(
106
- fn=generate_audio,
107
- inputs=[text_input, length_input, guidance_scale_input, guidance_rescale_input, ddim_steps_input, eta_input,
108
- random_seed_input, randomize_seed],
109
- outputs=output_audio,
110
- title="EzAudio Text-to-Audio Generator",
111
- description="Generate audio from text using a diffusion model. Adjust advanced settings for more control.",
112
- allow_flagging="never"
113
- ).launch()
114
-
115
-
116
- if __name__ == "__main__":
117
- gradio_interface()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  return params['autoencoder']['sr'], pred
84
 
85
 
86
+ # Examples (if needed for the demo)
87
+ examples = [
88
+ "the sound of rain falling softly",
89
+ "a dog barking in the distance",
90
+ "light guitar music is playing",
91
+ ]
92
+
93
+ # CSS styling (optional)
94
+ css = """
95
+ #col-container {
96
+ margin: 0 auto;
97
+ max-width: 1280px;
98
+ }
99
+ """
100
+
101
+ # Gradio Blocks layout
102
+ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
103
+ with gr.Column(elem_id="col-container"):
104
+ gr.Markdown("""
105
+ # EzAudio Text-to-Audio Generator
106
+ Generate audio from text using a diffusion transformer. Adjust advanced settings for more control.
107
+ """)
108
+
109
+ # Basic Input: Text prompt and Audio Length
110
+ with gr.Row():
111
+ text_input = gr.Textbox(
112
+ label="Text Prompt",
113
+ show_label=False,
114
+ max_lines=2,
115
+ placeholder="Enter your prompt",
116
+ container=False,
117
+ value="a dog barking in the distance"
118
+ )
119
+ length_input = gr.Slider(minimum=1, maximum=10, step=1, value=10, label="Audio Length (in seconds)")
120
+
121
+ # Output Component
122
+ result = gr.Audio(label="Result", type="numpy")
123
+
124
+ # Advanced settings in an Accordion
125
+ with gr.Accordion("Advanced Settings", open=False):
126
+ guidance_scale = gr.Slider(minimum=1.0, maximum=10, step=0.1, value=5.0, label="Guidance Scale")
127
+ guidance_rescale = gr.Slider(minimum=0.0, maximum=1, step=0.05, value=0.75, label="Guidance Rescale")
128
+ ddim_steps = gr.Slider(minimum=25, maximum=200, step=5, value=100, label="DDIM Steps")
129
+ eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1.0, label="Eta")
130
+ seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0, label="Seed")
131
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=False)
132
+
133
+ # Examples block
134
+ gr.Examples(
135
+ examples=examples,
136
+ inputs=[text_input]
137
+ )
138
+
139
+ # Run button
140
+ run_button = gr.Button("Generate")
141
+
142
+ # Define the trigger and input-output linking
143
+ run_button.click(
144
+ fn=generate_audio,
145
+ inputs=[text_input, length_input, guidance_scale, guidance_rescale, ddim_steps, eta, seed, randomize_seed],
146
+ outputs=[result]
147
+ )
148
+
149
+ # Launch the Gradio demo
150
+ demo.launch()