bharat-raghunathan commited on
Commit
65995d6
1 Parent(s): fc105fe

App updates to make it accept negative prompts and other hyperparams

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -7,23 +7,39 @@ sd_dreambooth_model = models.StableDiffusion(
7
  )
8
  db_diffusion_model = from_pretrained_keras("bharat-raghunathan/dreambooth_dosa")
9
  sd_dreambooth_model._diffusion_model = db_diffusion_model
10
- gr.HTML("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\">Keras Dreambooth - The Humble Dosa</h2>")
11
- gr.HTML("<p style=\"font-size: 14; font-weight: normal\" align=\"left\">This model has been fine-tuned to learn the concept of a dosa.")
12
  # generate images
13
- def infer(prompt):
14
  generated_images = sd_dreambooth_model.text_to_image(
15
- prompt
 
 
 
 
16
  )
17
  return generated_images
18
-
19
 
20
- output = gr.Gallery(label="Outputs").style(grid=(2,2))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- gr.Examples([["realistic picture of a man eating a dosa"],
23
- ["realistic picture of a dosa on a plate"],
24
- ["realistic picture of a dosa in a restaurant"],
25
- ],
26
- [prompt], gallery, generate_images, cache_examples=True)
27
- gr.Markdown('Demo created by [Bharat Raghunathan](https://huggingface.co/bharat-raghunathan/)')
28
  # pass function, input type for prompt, the output for multiple images
29
- gr.Interface(infer, inputs=["text"], outputs=[output]).launch()
 
7
  )
8
  db_diffusion_model = from_pretrained_keras("bharat-raghunathan/dreambooth_dosa")
9
  sd_dreambooth_model._diffusion_model = db_diffusion_model
10
+
 
11
  # generate images
12
+ def generate_images(prompt, negative_prompt, num_imgs_to_gen, num_steps, guidance_scale):
13
  generated_images = sd_dreambooth_model.text_to_image(
14
+ prompt,
15
+ negative_prompt=negative_prompt,
16
+ batch_size=num_imgs_to_gen,
17
+ num_steps=num_steps,
18
+ unconditional_guidance_scale=guidance_scale
19
  )
20
  return generated_images
 
21
 
22
+ with gr.Blocks() as demo:
23
+ gr.HTML("<h2 style=\"font-size: 2em; font-weight: bold\" align=\"center\">Keras Dreambooth - The Humble Dosa</h2>")
24
+ gr.HTML("<p style=\"font-size: 14; font-weight: normal\" align=\"left\">This model has been fine-tuned to learn the concept of a dosa.<br>To use this demo, insert the string <q>bhr dosa</q> in your prompt</p>")
25
+ with gr.Row():
26
+ with gr.Column():
27
+ prompt = gr.Textbox(lines=1, value="bhr dosa", label="Prompt")
28
+ negative_prompt = gr.Textbox(lines=1, value="deformed", label="Negative Prompt")
29
+ samples = gr.Slider(minimum=1, maximum=4, default=1, step=1, label="Number of Images")
30
+ num_steps = gr.Slider(label="Inference Steps", value=50)
31
+ guidance_scale = gr.Slider(label="Guidance Scale", minimum=1, maximum=12, default=7.5, step=0.5, label="Guidance Scale")
32
+ run = gr.Button(value="Run")
33
+ with gr.Column():
34
+ gallery = gr.Gallery(label="Outputs").style(grid=(2,2))
35
+
36
+ run.click(fn=generate_images, inputs=[prompt, negative_prompt, samples, num_steps, guidance_scale], outputs=gallery)
37
 
38
+ gr.Examples([["realistic picture of a man eating a bhr dosa", "home", 1, 50, 7.5],
39
+ ["realistic picture of a bhr dosa on a plate", "chutney", 1, 50, 7.5],
40
+ ["realistic picture of a bhr dosa in a restaurant", "sambar", 1, 50, 7.5],
41
+ ],
42
+ [prompt, negative_prompt, samples, num_steps, guidance_scale], gallery, generate_images, cache_examples=True)
43
+ gr.Markdown('Demo created by [Bharat Raghunathan](https://huggingface.co/bharat-raghunathan/)')
44
  # pass function, input type for prompt, the output for multiple images
45
+ demo.queue(concurrency_count=2).launch()