Nicholas Bady commited on
Commit ·
d1e97d4
1
Parent(s): 7fe717d
Upload 9 files
Browse filesFiles changed (9)
- DockerfileAdded+32
- README.mdAdded+89
- app.pyAdded+27
- banana_config.jsonAdded+26
- download.pyAdded+6
- inference.pyAdded
- prepare.pyAdded+2
- script.pyAdded+62
- server.pyAdded+7
1234567891011121314151617181920212223242526272829303132FROM nvidia/cuda:11.7.1-runtime-ubuntu22.04 RUN apt update && apt-get -y install git wget \ python3.10 python3.10-venv python3-pip \ build-essential libgl-dev libglib2.0-0 vimRUN ln -s /usr/bin/python3.10 /usr/bin/python
RUN useradd -ms /bin/bash bananaWORKDIR /app
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ cd stable-diffusion-webui && \ git checkout 3e0f9a75438fa815429b5530261bcf7d80f3f101WORKDIR /app/stable-diffusion-webui
#RUN wget -O models/Stable-diffusion/model.safetensors 'https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'RUN wget -O models/Stable-diffusion/model.ckpt 'https://huggingface.co/Vadermusic/playingaround/blob/main/liberty_main.ckpt'RUN echo 2ADD prepare.py .RUN python prepare.py --skip-torch-cuda-test --xformers --reinstall-torch --reinstall-xformers
ADD download.py download.pyRUN python download.py --use-cpu=all
RUN pip install dill
RUN mkdir -p extensions/banana/scriptsADD script.py extensions/banana/scripts/banana.pyADD app.py app.pyADD server.py server.py
CMD ["python", "server.py", "--xformers", "--disable-safe-unpickle", "--lowram", "--no-half", "--no-hashing", "--listen", "--port", "8000"]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
# 🍌 Stable Diffusion WebUI for banana (Stable Diffusion 1.5)
Deploy an API for AUTOMATIC1111's [Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) to generate images with **Stable Diffusion 1.5**.
Supports features not available in other Stable Diffusion templates, such as:
* [Prompt emphasis](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#attentionemphasis)* [Prompt editing](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#prompt-editing)* [Unlimited prompt length](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#infinite-prompt-length)
This deployment provides an API only and does not include the WebUI's user interface. Please report any issues you encounter.
## Instant Deploy
[See how to deploy in seconds](https://app.banana.dev/templates/patienceai/stable-diffusion-1.5-automatic1111).
## Model Inputs
### txt2img example
```{ "endpoint": "txt2img", "params": { "prompt": "an astronaut riding a (horse:motorcycle:0.5) on the moon", "negative_prompt": "cartoonish, low quality", "steps": 25, "sampler_name": "Euler a", "cfg_scale": 7.5, "seed": 42, "batch_size": 1, "n_iter": 1, "width": 512, "height": 512, "tiling": false }}```
(Only `prompt` is required.)
Output:
```{ "images": [ "<base64 image>" ]}```
### img2img example
```{ "endpoint": "img2img", "params": { "prompt": "an astronaut riding a horse on the moon in anime style", "negative_prompt": "cartoonish, low quality", "steps": 25, "sampler_name": "Euler a", "cfg_scale": 7.5, "denoising_strength": 0.7, "seed": 42, "batch_size": 1, "n_iter": 1, "width": 512, "height": 512, "tiling": false "init_images": [ "<base64 image>" ] }}```
(Only `prompt` and `init_images` are required.)
Output:
```{ "images": [ "<base64 image>" ]}```123456789101112131415161718192021222324252627import torchimport modules.safe as safeimport webui
torch.load = safe.unsafe_torch_loaddevice = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
def noop(*args, **kwargs): pass
def register_model(): global model try: from modules import shared, sd_hijack shared.sd_model = model sd_hijack.model_hijack.hijack(model) except: print("Failed to hijack model.")
def init(): global model import modules.sd_models modules.sd_models.list_models() modules.sd_models.list_models = noop model = modules.sd_models.load_model() modules.sd_models.load_model = noop register_model()1234567891011121314151617181920212223242526{ "name": "AUTOMATIC1111 - Stable Diffusion v1.5", "category": "Computer Vision", "example_input": { "endpoint": "txt2img", "params": { "prompt": "an astronaut riding a (horse:motorcycle:0.5) on the moon", "negative_prompt": "cartoonish, low quality", "steps": 25, "sampler_name": "Euler a", "cfg_scale": 7.5, "seed": 42, "batch_size": 1, "n_iter": 1, "width": 512, "height": 512, "tiling": false } }, "example_output": { "images": [ "<base64 output>" ] }, "version": "1"}123456from webui import initializeimport modules.interrogateinitialize()interrogator = modules.interrogate.InterrogateModels("interrogate")interrogator.load()interrogator.categories()12from launch import prepare_environmentprepare_environment()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import jsonimport requestsimport subprocessfrom fastapi import FastAPI, Request, Bodyfrom fastapi.testclient import TestClientfrom modules.script_callbacks import on_app_started
client = None
def healthcheck(): gpu = False out = subprocess.run("nvidia-smi", shell=True) if out.returncode == 0: # success state on shell command gpu = True return {"state": "healthy", "gpu": gpu}
async def inference(request: Request): global client body = await request.body() model_input = json.loads(body) params = None mode = 'default'
if 'endpoint' in model_input: endpoint = model_input['endpoint'] if 'params' in model_input: params = model_input['params'] else: mode = 'banana_compat' endpoint = 'txt2img' params = model_input
if endpoint == 'txt2img': if 'num_inference_steps' in params: params['steps'] = params['num_inference_steps'] del params['num_inference_steps'] if 'guidance_scale' in params: params['cfg_scale'] = params['guidance_scale'] del params['guidance_scale']
if params is not None: response = client.post('/sdapi/v1/' + endpoint, json = params) else: response = client.get('/sdapi/v1/' + endpoint)
output = response.json()
if mode == 'banana_compat' and 'images' in output: output = { "base64_output": output["images"][0] }
return output
def register_endpoints(block, app): global client app.add_api_route('/healthcheck', healthcheck, methods=['GET']) app.add_api_route('/', inference, methods=['POST']) client = TestClient(app)
on_app_started(register_endpoints)1234567import webuiimport app as user_src
user_src.init()
if __name__ == '__main__': webui.api_only()DockerfileAdded+32
README.mdAdded+89
app.pyAdded+27
banana_config.jsonAdded+26
download.pyAdded+6
inference.pyAdded
prepare.pyAdded+2
script.pyAdded+62
server.pyAdded+7