nielsgl commited on
Commit
f1d405b
·
1 Parent(s): 3c130f9

update app

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -17,30 +17,30 @@ resolution = 512
17
  # sd_dreambooth_model._diffusion_model = db_diffusion_model
18
 
19
  # checkpoint of the converted Stable Diffusion from KerasCV
20
- # model_ckpt = "nielsgl/dreambooth-keras-pug-ace-sd2.1"
21
- # pipeline = StableDiffusionPipeline.from_pretrained(model_ckpt)
22
- # pipeline.to("cuda")
23
 
24
- # unique_id = "puggieace"
25
- # class_label = "dog"
26
- # prompt = f"A photo of {unique_id} {class_label} in a bucket"
27
- # image = pipeline(prompt, num_inference_steps=50).images[0]
28
 
29
  # generate images
30
- # def infer(prompt, negative_prompt, guidance_scale=10, num_inference_steps=50):
31
- # neg = negative_prompt if negative_prompt else None
32
- # imgs = []
33
- # while len(imgs) != 2:
34
- # next_prompt = pipeline(prompt, negative_prompt=neg, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, num_images_per_prompt=5)
35
- # for img, is_neg in zip(next_prompt.images, next_prompt.nsfw_content_detected):
36
- # if not is_neg:
37
- # imgs.append(img)
38
- # if len(imgs) == 2:
39
- # break
40
 
41
- # return imgs
42
 
43
- # output = gr.Gallery(label="Outputs").style(grid=(1,2))
44
 
45
  # customize interface
46
  title = "KerasCV Stable Diffusion Demo on images of Ace."
@@ -161,12 +161,12 @@ The following hyperparameters were used during training for Stable Diffusion v1.
161
  with gr.Blocks() as card_interface:
162
  gr.Markdown(model_card)
163
 
164
- # demo_interface = gr.Interface(infer, inputs=[gr.Textbox(label="Positive Prompt", value="a photo of puggieace dog getting a haircut"),
165
- # gr.Textbox(label="Negative Prompt", value="bad anatomy, blurry"),
166
- # # gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
167
- # gr.Number(label='Guidance scale', value=12),
168
- # gr.Slider(label="Inference Steps",value=50),
169
- # ], outputs=[output], title=title, description=description, examples=examples).queue()
170
 
171
 
172
- gr.TabbedInterface([card_interface], ["Model Card"]).launch()
 
17
  # sd_dreambooth_model._diffusion_model = db_diffusion_model
18
 
19
  # checkpoint of the converted Stable Diffusion from KerasCV
20
+ model_ckpt = "nielsgl/dreambooth-keras-pug-ace-sd2.1"
21
+ pipeline = StableDiffusionPipeline.from_pretrained(model_ckpt)
22
+ pipeline.to("cuda")
23
 
24
+ unique_id = "puggieace"
25
+ class_label = "dog"
26
+ prompt = f"A photo of {unique_id} {class_label} on the beach"
27
+ image = pipeline(prompt, num_inference_steps=50).images[0]
28
 
29
  # generate images
30
+ def infer(prompt, negative_prompt, guidance_scale=10, num_inference_steps=50):
31
+ neg = negative_prompt if negative_prompt else None
32
+ imgs = []
33
+ while len(imgs) != 2:
34
+ next_prompt = pipeline(prompt, negative_prompt=neg, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, num_images_per_prompt=5)
35
+ for img, is_neg in zip(next_prompt.images, next_prompt.nsfw_content_detected):
36
+ if not is_neg:
37
+ imgs.append(img)
38
+ if len(imgs) == 2:
39
+ break
40
 
41
+ return imgs
42
 
43
+ output = gr.Gallery(label="Outputs").style(grid=(1,2))
44
 
45
  # customize interface
46
  title = "KerasCV Stable Diffusion Demo on images of Ace."
 
161
  with gr.Blocks() as card_interface:
162
  gr.Markdown(model_card)
163
 
164
+ demo_interface = gr.Interface(infer, inputs=[gr.Textbox(label="Positive Prompt", value="a photo of puggieace dog getting a haircut"),
165
+ gr.Textbox(label="Negative Prompt", value="bad anatomy, blurry"),
166
+ # gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
167
+ gr.Number(label='Guidance scale', value=12),
168
+ gr.Slider(label="Inference Steps",value=50),
169
+ ], outputs=[output], title=title, description=description, examples=examples).queue()
170
 
171
 
172
+ gr.TabbedInterface([card_interface, demo_interface], ["Model Card", "Demo 🤗"]).launch()