Melanit commited on
Commit
f5e0820
·
1 Parent(s): c62f777

Add guidance_scale as parameter to gradio app

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -12,13 +12,14 @@ dreambooth_model = keras_cv.models.StableDiffusion(
12
  loaded_diffusion_model = from_pretrained_keras("melanit/dreambooth_voyager_v2")
13
  dreambooth_model._diffusion_model = loaded_diffusion_model
14
 
15
- def generate_images(prompt: str, negative_prompt:str, batch_size: int, num_steps: int):
16
  """
17
  This function will infer the trained dreambooth (stable diffusion) model
18
  Args:
19
  prompt (str): The input text
20
  batch_size (int): The number of images to be generated
21
  num_steps (int): The number of denoising steps
 
22
  Returns:
23
  outputs (List): List of images that were generated using the model
24
  """
@@ -27,6 +28,7 @@ def generate_images(prompt: str, negative_prompt:str, batch_size: int, num_steps
27
  negative_prompt=negative_prompt,
28
  batch_size=batch_size,
29
  num_steps=num_steps,
 
30
  )
31
 
32
  return outputs
@@ -39,14 +41,15 @@ with gr.Blocks() as demo:
39
  negative_prompt = gr.Textbox(lines=1, value="", label="Negative Prompt")
40
  samples = gr.Slider(minimum=1, maximum=10, value=1, step=1, label="Number of Images")
41
  num_steps = gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Denoising Steps")
 
42
  run = gr.Button(value="Run")
43
  with gr.Column():
44
  gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
45
 
46
- run.click(generate_images, inputs=[prompt,negative_prompt, samples, num_steps], outputs=gallery)
47
 
48
- gr.Examples([["photo of voyager spaceship in space, high quality, blender, 3d, trending on artstation, 8k","bad, ugly, malformed, deformed, out of frame, blurry", 1, 50]],
49
- [prompt,negative_prompt, samples,num_steps], gallery, generate_images)
50
  gr.Markdown('Demo created by [Lily Berkow](https://huggingface.co/melanit/)')
51
 
52
  demo.launch()
 
12
  loaded_diffusion_model = from_pretrained_keras("melanit/dreambooth_voyager_v2")
13
  dreambooth_model._diffusion_model = loaded_diffusion_model
14
 
15
+ def generate_images(prompt: str, negative_prompt:str, batch_size: int, num_steps: int, guidance_scale: float):
16
  """
17
  This function will infer the trained dreambooth (stable diffusion) model
18
  Args:
19
  prompt (str): The input text
20
  batch_size (int): The number of images to be generated
21
  num_steps (int): The number of denoising steps
22
+ guidance_scale (float): The Guidance Scale
23
  Returns:
24
  outputs (List): List of images that were generated using the model
25
  """
 
28
  negative_prompt=negative_prompt,
29
  batch_size=batch_size,
30
  num_steps=num_steps,
31
+ unconditional_guidance_scale=guidance_scale
32
  )
33
 
34
  return outputs
 
41
  negative_prompt = gr.Textbox(lines=1, value="", label="Negative Prompt")
42
  samples = gr.Slider(minimum=1, maximum=10, value=1, step=1, label="Number of Images")
43
  num_steps = gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Denoising Steps")
44
+ guidance_scale = gr.Slider(value=7.5, step=0.5, label="Guidance scale")
45
  run = gr.Button(value="Run")
46
  with gr.Column():
47
  gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
48
 
49
+ run.click(generate_images, inputs=[prompt, negative_prompt, samples, num_steps, guidance_scale], outputs=gallery)
50
 
51
+ gr.Examples([["photo of voyager spaceship in space, high quality, blender, 3d, trending on artstation, 8k","bad, ugly, malformed, deformed, out of frame, blurry", 1, 50, 7.5]],
52
+ [prompt, negative_prompt, samples, num_steps, guidance_scale], gallery, generate_images)
53
  gr.Markdown('Demo created by [Lily Berkow](https://huggingface.co/melanit/)')
54
 
55
  demo.launch()