Fabrice-TIERCELIN commited on
Commit
e206c8a
β€’
1 Parent(s): 7b7c424

Use accordion

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -47,12 +47,12 @@ class Tango:
47
  self.scheduler = DDPMScheduler.from_pretrained(main_config["scheduler_name"], subfolder = "scheduler")
48
 
49
  def chunks(self, lst, n):
50
- """ Yield successive n-sized chunks from a list. """
51
  for i in range(0, len(lst), n):
52
  yield lst[i:i + n]
53
 
54
  def generate(self, prompt, steps = 100, guidance = 3, samples = 1, disable_progress = True):
55
- """ Generate audio for a single prompt string. """
56
  with torch.no_grad():
57
  latents = self.model.inference([prompt], self.scheduler, steps, guidance, samples, disable_progress = disable_progress)
58
  mel = self.vae.decode_first_stage(latents)
@@ -60,7 +60,7 @@ class Tango:
60
  return wave[0]
61
 
62
  def generate_for_batch(self, prompts, steps = 200, guidance = 3, samples = 1, batch_size = 8, disable_progress = True):
63
- """ Generate audio for a list of prompt strings. """
64
  outputs = []
65
  for k in tqdm(range(0, len(prompts), batch_size)):
66
  batch = prompts[k: k + batch_size]
@@ -80,7 +80,19 @@ tango.vae.to(device_type)
80
  tango.stft.to(device_type)
81
  tango.model.to(device_type)
82
 
83
- def gradio_generate(prompt, steps, guidance):
 
 
 
 
 
 
 
 
 
 
 
 
84
  output_wave = tango.generate(prompt, steps, guidance)
85
  return gr.make_waveform((16000, output_wave))
86
 
@@ -106,14 +118,19 @@ with gr.Blocks() as interface:
106
  """
107
  )
108
  input_text = gr.Textbox(label = "Prompt", value = "Snort of a horse", lines = 2, autofocus = True)
109
- denoising_steps = gr.Slider(label = "Steps", minimum = 100, maximum = 200, value = 100, step = 1, interactive = True)
110
- guidance_scale = gr.Slider(label = "Guidance Scale", minimum = 1, maximum = 10, value = 3, step = 0.1, interactive = True)
 
111
 
112
  submit = gr.Button("Generate πŸš€", variant = "primary")
113
 
114
  output_audio = gr.Audio(label = "Generated Audio")
115
 
116
- submit.click(fn = gradio_generate, inputs = [
 
 
 
 
117
  input_text,
118
  denoising_steps,
119
  guidance_scale
@@ -122,7 +139,7 @@ with gr.Blocks() as interface:
122
  ], scroll_to_output = True)
123
 
124
  gr.Examples(
125
- fn = gradio_generate,
126
  inputs = [
127
  input_text,
128
  denoising_steps,
 
47
  self.scheduler = DDPMScheduler.from_pretrained(main_config["scheduler_name"], subfolder = "scheduler")
48
 
49
  def chunks(self, lst, n):
50
+ # Yield successive n-sized chunks from a list
51
  for i in range(0, len(lst), n):
52
  yield lst[i:i + n]
53
 
54
  def generate(self, prompt, steps = 100, guidance = 3, samples = 1, disable_progress = True):
55
+ # Generate audio for a single prompt string
56
  with torch.no_grad():
57
  latents = self.model.inference([prompt], self.scheduler, steps, guidance, samples, disable_progress = disable_progress)
58
  mel = self.vae.decode_first_stage(latents)
 
60
  return wave[0]
61
 
62
  def generate_for_batch(self, prompts, steps = 200, guidance = 3, samples = 1, batch_size = 8, disable_progress = True):
63
+ # Generate audio for a list of prompt strings
64
  outputs = []
65
  for k in tqdm(range(0, len(prompts), batch_size)):
66
  batch = prompts[k: k + batch_size]
 
80
  tango.stft.to(device_type)
81
  tango.model.to(device_type)
82
 
83
+ def check(
84
+ prompt,
85
+ steps,
86
+ guidance
87
+ ):
88
+ if prompt is None or prompt == "":
89
+ raise gr.Error("Please provide a prompt input.")
90
+
91
+ def text2audio(
92
+ prompt,
93
+ steps,
94
+ guidance
95
+ ):
96
  output_wave = tango.generate(prompt, steps, guidance)
97
  return gr.make_waveform((16000, output_wave))
98
 
 
118
  """
119
  )
120
  input_text = gr.Textbox(label = "Prompt", value = "Snort of a horse", lines = 2, autofocus = True)
121
+ with gr.Accordion("Advanced options", open = False):
122
+ denoising_steps = gr.Slider(label = "Steps", info = "lower=faster & variant, higher=audio quality & similar", minimum = 100, maximum = 200, value = 100, step = 1, interactive = True)
123
+ guidance_scale = gr.Slider(label = "Guidance Scale", info = "lower=audio quality, higher=follow the prompt", minimum = 1, maximum = 10, value = 3, step = 0.1, interactive = True)
124
 
125
  submit = gr.Button("Generate πŸš€", variant = "primary")
126
 
127
  output_audio = gr.Audio(label = "Generated Audio")
128
 
129
+ submit.click(fn = check, inputs = [
130
+ input_text,
131
+ denoising_steps,
132
+ guidance_scale
133
+ ], outputs = [], queue = False, show_progress = False).success(fn = text2audio, inputs = [
134
  input_text,
135
  denoising_steps,
136
  guidance_scale
 
139
  ], scroll_to_output = True)
140
 
141
  gr.Examples(
142
+ fn = text2audio,
143
  inputs = [
144
  input_text,
145
  denoising_steps,