Skip to content

Commit

Permalink
Uploaded example for stable diffusion
Browse files Browse the repository at this point in the history
  • Loading branch information
esparig committed Nov 26, 2024
1 parent 39785dd commit 1d566ea
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/stable-diffusion/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions examples/stable-diffusion/README.md
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions examples/stable-diffusion/prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a chicken making a 360 with a skateboard with background flames
Binary file added examples/stable-diffusion/prompt.txt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions examples/stable-diffusion/script.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions examples/stable-diffusion/stable-diff.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1d566ea

Please sign in to comment.