Skip to content

Commit

Permalink
Update gradio_app.py
Browse files Browse the repository at this point in the history
Ref to Update 0.4
  • Loading branch information
Saganaki22 authored Jun 10, 2024
1 parent a8b0a71 commit 34f7624
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gradio_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from datetime import datetime
import gradio as gr

# Define a function to toggle the visibility of the seed slider
def toggle_seed_slider(x):
seed_slider.visible = not x

# Define a function to set up the model and device
def setup_model(model_half):
model, model_config = get_pretrained_model("audo/stable-audio-open-1.0")
Expand Down Expand Up @@ -88,7 +92,7 @@ def generate_audio(prompt, steps, cfg_scale, sigma_min, sigma_max, generation_ti

return full_path

def audio_generator(prompt, sampler_type, steps, cfg_scale, sigma_min, sigma_max, generation_time, seed, model_half):
def audio_generator(prompt, sampler_type, steps, cfg_scale, sigma_min, sigma_max, generation_time, random_seed, seed, model_half):
try:
print("Generating audio with parameters:")
print("Prompt:", prompt)
Expand All @@ -98,12 +102,16 @@ def audio_generator(prompt, sampler_type, steps, cfg_scale, sigma_min, sigma_max
print("Sigma Min:", sigma_min)
print("Sigma Max:", sigma_max)
print("Generation Time:", generation_time)
print("Random Seed:", "Random" if random_seed else "Fixed")
print("Seed:", seed)
print("Model Half Precision:", model_half)

# Set up the model and device
model, model_config, device = setup_model(model_half)

if random_seed:
seed = torch.randint(0, 1000000, (1,)).item()

filename = generate_audio(prompt, steps, cfg_scale, sigma_min, sigma_max, generation_time, seed, sampler_type, model_half, model, model_config, device)
return gr.Audio(filename), f"Generated: {filename}"
except Exception as e:
Expand All @@ -130,6 +138,7 @@ def audio_generator(prompt, sampler_type, steps, cfg_scale, sigma_min, sigma_max
)
steps_slider = gr.Slider(minimum=0, maximum=200, label="Steps", step=1, value=100)
generation_time_slider = gr.Slider(minimum=0, maximum=47, label="Generation Time (seconds)", step=1, value=47)
random_seed_checkbox = gr.Checkbox(label="Random Seed")
seed_slider = gr.Slider(minimum=-1, maximum=999999, label="Seed", step=1, value=123456)

# Advanced parameters accordion
Expand All @@ -147,8 +156,9 @@ def audio_generator(prompt, sampler_type, steps, cfg_scale, sigma_min, sigma_max
output_textbox = gr.Textbox(label="Output")

# Link the button and the function
random_seed_checkbox.change(fn=toggle_seed_slider, inputs=[random_seed_checkbox], outputs=[seed_slider])
submit_button.click(audio_generator,
inputs=[prompt_textbox, sampler_dropdown, steps_slider, cfg_scale_slider, sigma_min_slider, sigma_max_slider, generation_time_slider, seed_slider, model_half_checkbox],
inputs=[prompt_textbox, sampler_dropdown, steps_slider, cfg_scale_slider,sigma_min_slider, sigma_max_slider, generation_time_slider, random_seed_checkbox, seed_slider, model_half_checkbox],
outputs=[audio_output, output_textbox])

# GitHub link at the bottom
Expand Down

0 comments on commit 34f7624

Please sign in to comment.