Johannes commited on
Commit
d7f77a0
·
1 Parent(s): 82bdc0d
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +48 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_keras
2
+ import keras_cv
3
+ import gradio as gr
4
+ from tensorflow import keras
5
+
6
+ keras.mixed_precision.set_global_policy("mixed_float16")
7
+ # load keras model
8
+ resolution = 512
9
+ dreambooth_model = keras_cv.models.StableDiffusion(
10
+ img_width=resolution, img_height=resolution, jit_compile=True,
11
+ )
12
+ loaded_diffusion_model = from_pretrained_keras("johko/monkey_island_style")
13
+ dreambooth_model._diffusion_model = loaded_diffusion_model
14
+
15
+
16
+ def generate_images(prompt: str, negative_prompt: str, num_imgs_to_gen: int, num_steps: int, guidance_scale: float):
17
+ generated_img = dreambooth_model.text_to_image(
18
+ prompt,
19
+ negative_prompt=negative_prompt,
20
+ batch_size=num_imgs_to_gen,
21
+ num_steps=num_steps,
22
+ unconditional_guidance_scale=guidance_scale,
23
+ )
24
+
25
+ return generated_img
26
+
27
+
28
+ # pass function, input type for prompt, the output for multiple images
29
+ gr.Interface(
30
+ title="Keras Dreambooth - Monkey Island Style 🐒",
31
+ description="""This SD model has been fine-tuned to learn the art style of the game *Return To Monkey Island* using Dreambooth.
32
+ While not being perfect at imitating the stlye, my experiments have shown that it works best on fictional characters, such as Geralt of Rivia, Frodo Baggins or Harry Potter.
33
+
34
+ To use the new style make sure to include `in mnky style` to your prompt.
35
+ """,
36
+ fn=generate_images,
37
+ inputs=[
38
+ gr.Textbox(label="Positive Prompt", value="a photo of paranoid marvin a robot"),
39
+ gr.Textbox(label="Negative Prompt", value="low quality, deformed"),
40
+ gr.Slider(label='Number of gen image', minimum=1, maximum=4, value=2, step=1),
41
+ gr.Slider(label="Inference Steps", value=50),
42
+ gr.Slider(label='Guidance scale', value=7.5, maximum=15, minimum=0, step=0.5),
43
+ ],
44
+ outputs=[
45
+ gr.Gallery(show_label=False).style(grid=(1,2)),
46
+ ],
47
+ examples=[["geralt of rivia in mnky style, high quality, 4k, trending on artstation", "bad, ugly", 2, 70, 8]],
48
+ ).queue().launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ keras_cv
2
+ tensorflow