vilarin commited on
Commit
86a5e68
โ€ข
1 Parent(s): 02072e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -12,7 +12,7 @@ translator = Translator()
12
 
13
  # Constants
14
  model = "stabilityai/stable-audio-open-1.0"
15
- # MAX_SEED = np.iinfo(np.int32).max
16
 
17
  CSS = """
18
  .gradio-container {
@@ -41,8 +41,8 @@ a T5-based text embedding for text conditioning, and a transformer-based diffusi
41
  if torch.cuda.is_available():
42
  pipe = StableAudioPipeline.from_pretrained(
43
  model,
44
- low_cpu_mem_usage=True,
45
- torch_dtype=torch.float16).to("cuda")
46
 
47
 
48
  # Function
@@ -52,10 +52,10 @@ def main(
52
  negative="low quality",
53
  second: float = 10.0):
54
 
55
- # if seed == -1:
56
- # seed = random.randint(0, MAX_SEED)
57
- # seed = int(seed)
58
- # generator = torch.Generator().manual_seed(seed)
59
 
60
  prompt = str(translator.translate(prompt, 'English'))
61
 
@@ -65,6 +65,9 @@ def main(
65
  prompt,
66
  negative_prompt=negative,
67
  audio_end_in_s=second,
 
 
 
68
  ).audios
69
 
70
  os.makedirs("outputs", exist_ok=True)
@@ -73,26 +76,25 @@ def main(
73
 
74
  sf.write(audio_path, audio[0].T.float().cpu().numpy(), pipe.vae.samping_rate)
75
 
76
- return audio_path
77
 
78
  # Gradio Interface
79
 
80
  with gr.Blocks(theme='soft', css=CSS, js=JS, title="Stable Audio Open") as iface:
81
  with gr.Accordion(""):
82
  gr.Markdown(DESCRIPTION)
 
 
 
83
  with gr.Row():
84
- output = gr.Audio(label="Podcast", type="filepath", interactive=False, autoplay=True, elem_classes="audio") # Create an output textbox
85
- with gr.Row():
86
- prompt = gr.Textbox(label="Prompt", placeholder="1000 BPM percussive sound of water drops")
87
- with gr.Row():
88
- negative = gr.Textbox(label="Negative prompt", placeholder="Low quality")
89
  second = gr.Slider(5.0, 60.0, value=10.0, label="Second", step=0.1),
 
90
  with gr.Row():
91
  submit_btn = gr.Button("๐Ÿš€ Send") # Create a submit button
92
- clear_btn = gr.ClearButton(output, value="๐Ÿ—‘๏ธ Clear") # Create a clear button
93
 
94
  # Set up the event listeners
95
- submit_btn.click(main, inputs=[prompt, negative, second], outputs=output)
96
 
97
 
98
  #gr.close_all()
 
12
 
13
  # Constants
14
  model = "stabilityai/stable-audio-open-1.0"
15
+ MAX_SEED = np.iinfo(np.int32).max
16
 
17
  CSS = """
18
  .gradio-container {
 
41
  if torch.cuda.is_available():
42
  pipe = StableAudioPipeline.from_pretrained(
43
  model,
44
+ torch_dtype=torch.float16)
45
+ pipe = pipe.to("cuda")
46
 
47
 
48
  # Function
 
52
  negative="low quality",
53
  second: float = 10.0):
54
 
55
+ if seed == -1:
56
+ seed = random.randint(0, MAX_SEED)
57
+ seed = int(seed)
58
+ generator = torch.Generator().manual_seed(seed)
59
 
60
  prompt = str(translator.translate(prompt, 'English'))
61
 
 
65
  prompt,
66
  negative_prompt=negative,
67
  audio_end_in_s=second,
68
+ num_inference_steps=200,
69
+ num_waveforms_per_prompt=3,
70
+ generator=generator,
71
  ).audios
72
 
73
  os.makedirs("outputs", exist_ok=True)
 
76
 
77
  sf.write(audio_path, audio[0].T.float().cpu().numpy(), pipe.vae.samping_rate)
78
 
79
+ return audio_path, seed
80
 
81
  # Gradio Interface
82
 
83
  with gr.Blocks(theme='soft', css=CSS, js=JS, title="Stable Audio Open") as iface:
84
  with gr.Accordion(""):
85
  gr.Markdown(DESCRIPTION)
86
+ output = gr.Audio(label="Podcast", type="filepath", interactive=False, autoplay=True, elem_classes="audio") # Create an output textbox
87
+ prompt = gr.Textbox(label="Prompt", placeholder="1000 BPM percussive sound of water drops")
88
+ negative = gr.Textbox(label="Negative prompt", placeholder="Low quality")
89
  with gr.Row():
 
 
 
 
 
90
  second = gr.Slider(5.0, 60.0, value=10.0, label="Second", step=0.1),
91
+ seed = gr.Slider(1, MAX_SEED, value=0, label="Seed", step=1),
92
  with gr.Row():
93
  submit_btn = gr.Button("๐Ÿš€ Send") # Create a submit button
94
+ clear_btn = gr.ClearButton([prompt, seed, output], value="๐Ÿ—‘๏ธ Clear") # Create a clear button
95
 
96
  # Set up the event listeners
97
+ submit_btn.click(main, inputs=[prompt, negative, second, seed], outputs=[output, seed])
98
 
99
 
100
  #gr.close_all()