UdacityNoob commited on
Commit
bcbcd98
1 Parent(s): f7da7e5

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +4 -2
  2. app.py +51 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -8,6 +8,8 @@ sdk_version: 3.23.0
8
  app_file: app.py
9
  pinned: false
10
  license: creativeml-openrail-m
 
 
 
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  license: creativeml-openrail-m
11
+ tags:
12
+ - keras-dreambooth
13
+ - sci-fi
14
  ---
15
+ Demo space using the [dreambooth_hogwarts_legacy](https://huggingface.co/keras-dreambooth/dreambooth_hogwarts_legacy) model to draw a game character.
 
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_keras
2
+ from keras_cv import models
3
+ import gradio as gr
4
+ import tensorflow as tf
5
+
6
+ tf.keras.mixed_precision.set_global_policy("mixed_float16")
7
+
8
+ # load keras model
9
+ resolution = 512
10
+ dreambooth_model = models.StableDiffusion(
11
+ img_width=resolution, img_height=resolution, jit_compile=True,
12
+ )
13
+ loaded_diffusion_model = from_pretrained_keras("tgohblio/dreambooth_hogwarts_legacy")
14
+ dreambooth_model._diffusion_model = loaded_diffusion_model
15
+
16
+
17
+ # generate images
18
+ def generate_images(prompt: str, negative_prompt: str, num_imgs_to_gen: int, inference_steps: int, guidance_scale: float):
19
+ output_images = dreambooth_model.text_to_image(
20
+ prompt,
21
+ negative_prompt=negative_prompt,
22
+ batch_size=num_imgs_to_gen,
23
+ num_steps=inference_steps,
24
+ unconditional_guidance_scale=guidance_scale,
25
+ )
26
+ return output_images
27
+
28
+ # Define the UI
29
+ with gr.Blocks() as demo:
30
+ gr.HTML("<h2 style=\"font-size: 2rem; font-weight: 700; text-align: center;\">Keras Dreambooth - Hogwarts Legacy Demo</h2>")
31
+ gr.HTML("<h3 style=\"font-size: 2rem; font-weight: 700; text-align: left;\">This model has been fine-tuned to learn the concept of Hogwarts Legacy student characters. \
32
+ To use this demo, you should have append your prompt with string \'hogwarts [legacy] student\'</h3>")
33
+ with gr.Row():
34
+ with gr.Column():
35
+ prompt = gr.Textbox(label="Positive Prompt", value="a digital art of hogwarts [legacy] student in a forest")
36
+ negative_prompt = gr.Textbox(label="Negative Prompt", value="bad anatomy, soft blurry")
37
+ samples = gr.Slider(label="Number of Images", minimum=1, maximum=6, value=1, step=1)
38
+ inference_steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=50, step=1)
39
+ guidance_scale = gr.Slider(label="Guidance Scale", minimum=1, maximum=10, value=7.5, step=0.1)
40
+ run = gr.Button(value="Run")
41
+ with gr.Column():
42
+ gallery = gr.Gallery(label="Outputs").style(grid=(1,2))
43
+
44
+ run.click(fn=generate_images, inputs=[prompt, negative_prompt, samples, inference_steps, guidance_scale], outputs=gallery)
45
+
46
+ gr.Examples([["realistic painting of a hogwarts [legacy] student riding a horse, high quality, 8k", "bad, ugly, malformed, deformed, out of frame, blurry, cropped, noisy", 4, 100, 7.5]],
47
+ [prompt, negative_prompt, samples, inference_steps, guidance_scale], gallery, generate_images, cache_examples=True)
48
+ gr.Markdown('Demo created by [Terrence Goh](https://huggingface.co/tgohblio/)')
49
+
50
+ demo.queue(concurrency_count=3)
51
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ keras_cv
2
+ tensorflow==2.11.0
3
+ huggingface-hub
4
+ gradio