AmpleBasis commited on
Commit
3f81f99
·
1 Parent(s): 9b24785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -14
app.py CHANGED
@@ -8,23 +8,47 @@ keras.mixed_precision.set_global_policy("mixed_float16")
8
 
9
  # prepare model
10
  resolution = 512
11
- sd_dreambooth_model = models.StableDiffusion(
12
- img_width=resolution, img_height=resolution
13
- )
14
  db_diffusion_model = from_pretrained_keras("AmpleBasis/seymour-cat")
15
  sd_dreambooth_model._diffusion_model = db_diffusion_model
16
 
17
- # generate images
18
- def infer(prompt):
19
- generated_images = sd_dreambooth_model.text_to_image(
20
- prompt, batch_size=2
 
 
 
21
  )
22
- return generated_images
 
 
 
 
 
 
 
 
 
23
 
24
- output = gr.Gallery(label="Outputs").style(grid=(1,2))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # customize interface
27
- title = "Dreambooth Demo on Seymour the Cat"
28
- description = "This is a dreambooth model fine-tuned on images of Seymour the Cat. To try it, input the concept with {symr cat}."
29
- examples=[["photo of symr cat"]]
30
- gr.Interface(infer, inputs=["text"], outputs=[output], title=title, description=description, examples=examples).queue().launch()
 
8
 
9
  # prepare model
10
  resolution = 512
11
+ sd_dreambooth_model = keras_cv.models.StableDiffusion(
12
+ img_width=resolution, img_height=resolution, jit_compile=True,
13
+ )
14
  db_diffusion_model = from_pretrained_keras("AmpleBasis/seymour-cat")
15
  sd_dreambooth_model._diffusion_model = db_diffusion_model
16
 
17
+ def generate_images(prompt: str, negative_prompt:str, num_imgs_to_gen: int, num_steps: int, ugs: int):
18
+ generated_img = sd_dreambooth_model.text_to_image(
19
+ prompt,
20
+ negative_prompt=negative_prompt,
21
+ batch_size=num_imgs_to_gen,
22
+ num_steps=num_steps,
23
+ unconditional_guidance_scale=ugs,
24
  )
25
+
26
+ return generated_img
27
+
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("""
30
+ # Seymour Diffusion
31
+ This is a Keras Dreambooth model fine-tuned to images of Seymour, a cat.
32
+ The model, part of the [Keras Dreambooth Sprint](https://github.com/huggingface/community-events/tree/main/keras-dreambooth-sprint) trained by Pedro Pacheco, can be found in [AmpleBasis/seymour-cat](https://huggingface.co/AmpleBasis/seymour-cat).
33
+
34
+ The model should be used with a prompt containing `symr cat`. A typical prompt for this model is `photo of symr cat`.
35
 
36
+ """)
37
+ with gr.Row():
38
+ with gr.Column():
39
+ prompt = gr.Textbox(lines=1, value="photo of symr cat", label="Prompt")
40
+ negative_prompt = gr.Textbox(lines=1, value="deformed,blurry,lowres", label="Negative Prompt")
41
+ samples = gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of Images")
42
+ num_steps = gr.Slider(label="Steps",value=40)
43
+ ugs = gr.Slider(value=7, minimum=5, maximum=25, step=1, label="Unconditional Guidance Scale")
44
+ run = gr.Button(value="Generate")
45
+ with gr.Column():
46
+ gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
47
+
48
+ run.click(generate_images, inputs=[prompt,negative_prompt, samples, num_steps, ugs], outputs=gallery)
49
+
50
+ gr.Examples([["photo of symr cat", 1, 40, 7],
51
+
52
+ [prompt,negative_prompt, samples,num_steps, ugs], gallery, generate_images)
53
 
54
+ demo.launch(debug=True)