From 4ceccf78b20adba43df1933fc808b67dbc2f5231 Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Tue, 20 Sep 2022 17:21:10 +0300 Subject: [PATCH 1/3] Add WebUI --- Dockerfile | 18 +++++++++++++++ README.md | 12 +++++++--- requirements.txt | 4 +++- webui.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 webui.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1d66aaf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM tensorflow/tensorflow:latest-gpu + +ENV DEBIAN_FRONTEND noninteractive + +WORKDIR /app + +COPY requirements.txt /app + +RUN pip install --prefer-binary --no-cache-dir -q -r requirements.txt && \ + rm -rf ~/.cache + +COPY . /app/ + +VOLUME /root/.keras + +EXPOSE 7860 + +CMD ["python", "webui.py"] diff --git a/README.md b/README.md index 6c1c953..9eef82a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,13 @@ created by @divamgupta. The weights were ported from the original implementation python text2image.py --prompt="An astronaut riding a horse" ``` -3) Using the python interface: +3) Using the WebUI : + +``` +python webui.py +``` + +4) Using the python interface: ``` pip install git+https://github.com/fchollet/stable-diffusion-tensorflow @@ -26,7 +32,7 @@ pip install git+https://github.com/fchollet/stable-diffusion-tensorflow from stable_diffusion_tf.stable_diffusion import Text2Image from PIL import Image -generator = Text2Image( +generator = Text2Image( img_height=512, img_width=512, jit_compile=False, @@ -41,7 +47,7 @@ img = generator.generate( Image.fromarray(img[0]).save("output.png") ``` -## Example outputs +## Example outputs The following outputs have been generated using the this implementation: diff --git a/requirements.txt b/requirements.txt index b108e7e..abb5692 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ tensorflow==2.10.0 +tensorflow-addons==0.17.1 h5py==3.7.0 Pillow==9.2.0 tqdm==4.64.1 ftfy==6.1.1 -regex==2022.9.13 \ No newline at end of file +regex==2022.9.13 +gradio==3.3.1 diff --git a/webui.py b/webui.py new file mode 100644 index 0000000..6eebc6d --- /dev/null +++ b/webui.py @@ -0,0 +1,60 @@ +import gradio as gr +from stable_diffusion_tf.stable_diffusion import Text2Image + + +generator = Text2Image(img_height=512, img_width=512, jit_compile=False) + + +def infer(prompt, samples, steps, scale, seed): + return generator.generate( + prompt, + num_steps=steps, + unconditional_guidance_scale=scale, + temperature=1, + batch_size=samples, + seed=seed, + ) + + +block = gr.Blocks() + +with block: + with gr.Group(): + with gr.Box(): + with gr.Row().style(equal_height=True): + text = gr.Textbox( + label="Enter your prompt", + show_label=False, + max_lines=1, + placeholder="Enter your prompt", + ).style( + border=(True, False, True, True), + rounded=(True, False, False, True), + container=False, + ) + btn = gr.Button("Generate image").style( + margin=False, + rounded=(False, True, True, False), + ) + gallery = gr.Gallery( + label="Generated images", show_label=False, elem_id="gallery" + ).style(grid=[2], height="auto") + + advanced_button = gr.Button("Advanced options", elem_id="advanced-btn") + + with gr.Row(elem_id="advanced-options"): + samples = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1) + steps = gr.Slider(label="Steps", minimum=1, maximum=200, value=50, step=1) + scale = gr.Slider(label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1) + seed = gr.Slider( + label="Seed", + minimum=0, + maximum=2147483647, + step=1, + randomize=True + ) + text.submit(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery) + btn.click(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery) + advanced_button.click(None, [], text) + +block.launch(server_name='0.0.0.0') From 602ba161dd76918fe85a3e2bb3c6cccfc8b1a078 Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Wed, 21 Sep 2022 14:39:32 +0300 Subject: [PATCH 2/3] Add docker-compose.yml --- docker-compose.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1ce8dcb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3' + +services: + stable-diffusion-tf: + image: stable-diffusion-tf + build: . + volumes: + - keras:/root/.keras + ports: + - "7860:7860" + command: python3 webui.py + restart: unless-stopped + deploy: + resources: + reservations: + devices: + - driver: nvidia + device_ids: ['0'] + capabilities: [gpu] + +volumes: + keras: \ No newline at end of file From 94f425c91eb6bd63f3b9e71c1097adba55a65a2a Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Thu, 13 Oct 2022 18:29:23 +0300 Subject: [PATCH 3/3] refresh branch --- requirements.txt | 1 - webui.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index adc953b..891e542 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ tensorflow==2.10.0 -tensorflow-addons==0.17.1 h5py==3.7.0 Pillow==9.2.0 tqdm==4.64.1 diff --git a/webui.py b/webui.py index 6eebc6d..b496d6e 100644 --- a/webui.py +++ b/webui.py @@ -1,8 +1,8 @@ import gradio as gr -from stable_diffusion_tf.stable_diffusion import Text2Image +from stable_diffusion_tf.stable_diffusion import StableDiffusion -generator = Text2Image(img_height=512, img_width=512, jit_compile=False) +generator = StableDiffusion(img_height=512, img_width=512, jit_compile=False) def infer(prompt, samples, steps, scale, seed):