diff --git a/examples/stable-diffusion/Dockerfile b/examples/stable-diffusion/Dockerfile new file mode 100644 index 00000000..65bdbd95 --- /dev/null +++ b/examples/stable-diffusion/Dockerfile @@ -0,0 +1,21 @@ +FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 + +RUN apt update && \ + apt install -y --no-install-recommends git wget python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN git clone https://github.com/srisco/stable-diffusion-tensorflow.git + +WORKDIR stable-diffusion-tensorflow + +RUN pip install -r requirements.txt && \ + rm -rf /root/.cache/pip/* && \ + rm -rf /tmp/* + +# DOWNLOAD WEIGHTS +RUN mkdir -p /root/.keras/datasets && \ + wget https://huggingface.co/fchollet/stable-diffusion/resolve/main/text_encoder.h5 -O /root/.keras/datasets/text_encoder.h5 && \ + wget https://huggingface.co/fchollet/stable-diffusion/resolve/main/diffusion_model.h5 -O /root/.keras/datasets/diffusion_model.h5 && \ + wget https://huggingface.co/fchollet/stable-diffusion/resolve/main/decoder.h5 -O /root/.keras/datasets/decoder.h5 && \ + wget https://huggingface.co/divamgupta/stable-diffusion-tensorflow/resolve/main/encoder_newW.h5 -O /root/.keras/datasets/encoder_newW.h5 diff --git a/examples/stable-diffusion/README.md b/examples/stable-diffusion/README.md new file mode 100644 index 00000000..3f8b7512 --- /dev/null +++ b/examples/stable-diffusion/README.md @@ -0,0 +1,31 @@ +# Stable Diffusion + +This example is based on a Keras / Tensorflow implementation of Stable Diffusion. The following repositories were used for the creation of the image: + +* [srisco/stable-diffusion-tensorflow](https://github.com/srisco/stable-diffusion-tensorflow) +* [huggingface.co/fchollet/stable-diffusion](https://huggingface.co/fchollet/stable-diffusion) +* [huggingface.co/divamgupta/stable-diffusion-tensorflow](https://huggingface.co/divamgupta/stable-diffusion-tensorflow/) + +The image if pushed to a public github registry [here](ghcr.io/grycap/stable-diffusion-tf:latest) but you can see the Dockerfile that generates it [here](Dockerfile). + +## Deploy an OSCAR cluster +Follow the instructions in the documentation for your desired IaaS cloud provider. +[See Deployment](https://docs.oscar.grycap.net/) + +## Create the OSCAR Service + +The Service can be created using the OSCAR GUI by providing the [FDL](stable-diff.yaml) and the [script.sh](script.sh) file. + +![OSCAR GUI Creation of a service](https://oscar.grycap.net/images/blog/post-20210803-1/create_service_gui.png) + +## Upload the input file to the MinIO bucket + +Once the service is created, you can upload the input file to the bucket. The input file should be a file containing the prompt that you want to process. + +For example, using the following prompt: + +`a chicken making a 360 with a skateboard with background flames` + +The following image is generated: + +![Cool chicken](prompt.txt.png) \ No newline at end of file diff --git a/examples/stable-diffusion/prompt.txt b/examples/stable-diffusion/prompt.txt new file mode 100644 index 00000000..b27d4aad --- /dev/null +++ b/examples/stable-diffusion/prompt.txt @@ -0,0 +1 @@ +a chicken making a 360 with a skateboard with background flames diff --git a/examples/stable-diffusion/prompt.txt.png b/examples/stable-diffusion/prompt.txt.png new file mode 100644 index 00000000..543cffb6 Binary files /dev/null and b/examples/stable-diffusion/prompt.txt.png differ diff --git a/examples/stable-diffusion/script.sh b/examples/stable-diffusion/script.sh new file mode 100644 index 00000000..8bb41054 --- /dev/null +++ b/examples/stable-diffusion/script.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "SCRIPT: Invoked stable diffusion text to image." +FILE_NAME=`basename "$INPUT_FILE_PATH"` +OUTPUT_FILE="$TMP_OUTPUT_DIR/$FILE_NAME.png" + +prompt=`cat "$INPUT_FILE_PATH"` +echo "SCRIPT: Converting input prompt '$INPUT_FILE_PATH' to image :)" +python3 text2image.py --prompt="$prompt" --output=$OUTPUT_FILE \ No newline at end of file diff --git a/examples/stable-diffusion/stable-diff.yaml b/examples/stable-diffusion/stable-diff.yaml new file mode 100644 index 00000000..2ea74461 --- /dev/null +++ b/examples/stable-diffusion/stable-diff.yaml @@ -0,0 +1,17 @@ +functions: + oscar: + - oscar-intertwin: + name: stable-diffusion-tf + memory: 16Gi + cpu: '4' + image: ghcr.io/grycap/stable-diffusion-tf:latest + script: script.sh + log_level: DEBUG + vo: "vo.example.eu" + allowed_users: [] + input: + - storage_provider: minio.default + path: stablediff/input + output: + - storage_provider: minio.default + path: stablediff/output