ljcortesr commited on
Commit
559b897
·
1 Parent(s): 6d73fb7

Front and back

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -12,8 +12,27 @@ model = None
12
 
13
  @spaces.GPU
14
  def generate_audio(descriptions: str):
15
- print("generate audio called")
16
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  with gr.Blocks() as demo:
19
  gr.Markdown("# AudioGen Demo")
 
12
 
13
  @spaces.GPU
14
  def generate_audio(descriptions: str):
15
+ global model
16
+ if model is None:
17
+ model = AudioGen.get_pretrained('facebook/audiogen-medium')
18
+ model.set_generation_params(duration=10)
19
+
20
+ safe_name = "_".join(descriptions.split())
21
+ output_path = os.path.join(OUTPUT_DIR, safe_name)
22
+
23
+ wav = model.generate([descriptions])
24
+ audio_write(
25
+ output_path,
26
+ wav[0].cpu(),
27
+ model.sample_rate,
28
+ strategy="loudness",
29
+ loudness_compressor=True,
30
+ add_suffix=False,
31
+ )
32
+
33
+ final_path = f"{output_path}.wav"
34
+ print(f"Generated audio for '{descriptions}' -> {final_path}")
35
+ return final_path
36
 
37
  with gr.Blocks() as demo:
38
  gr.Markdown("# AudioGen Demo")