commit 4fbd3479f3023c94eb67ee9c64222d279374a402 Author: cmdr2 Date: Wed Aug 24 01:58:18 2022 +0530 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..bee8a64b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..4422b0ea --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 cmdr2 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..9047af94 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +A simple browser UI for generating images from text prompts, using [Stable Diffusion](https://replicate.com/stability-ai/stable-diffusion). Designed for running locally on your computer. + +This project runs Stable Diffusion in a docker container behind the scenes, using Stable Diffusion's official Docker image on replicate.com. + +![Screenshot of tool](shot1.jpeg?raw=true) + +# System Requirements +1. Requires `docker` and `python3.6` (or higher). +2. Linux or Windows 11 (with WSL) or macOS. Basically if your system can run [Stable Diffusion](https://replicate.com/stability-ai/stable-diffusion). + +# Installation +1. Download [Quick UI](https://github.com/cmdr2/stable-diffusion-ui/archive/refs/heads/main.zip) +2. Unzip: `unzip main.zip` +3. Enter: `cd stable-diffusion-ui` +4. Install dependencies: `pip install fastapi uvicorn` (this is the framework and server used by QuickUI) +5. Run: `./server.sh` +6. Open `http://localhost:8000` in your browser + +# Usage +1. Open `http://localhost:8000` in your browser +2. Enter a text prompt, like `a photograph of an astronaut riding a horse` in the textbox. +3. Press `Make Image`. This will take a while, depending on your system's processing power. +4. See the image generated using your prompt. If there's an error, the status message at the top will show 'error' in red. + +# Bugs reports and code contributions welcome +This was built in a few hours for fun. So if there are any problems, please feel free to file an issue. + +Also, if you have any code contributions, please feel to submit a pull request. \ No newline at end of file diff --git a/ding.mp3 b/ding.mp3 new file mode 100644 index 00000000..f2843b06 Binary files /dev/null and b/ding.mp3 differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..3381f06a --- /dev/null +++ b/index.html @@ -0,0 +1,150 @@ + + + + + + +

Stable Diffusion - Quick UI

+ +
Server status: checking.. | Request status: n/a
+ +
+ + Prompt:
+
+ +

+ + + + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 00000000..85322b14 --- /dev/null +++ b/main.py @@ -0,0 +1,42 @@ +from fastapi import FastAPI +from starlette.responses import FileResponse +from pydantic import BaseModel + +import requests + +LOCAL_SERVER_URL = 'http://localhost:5000' +PREDICT_URL = LOCAL_SERVER_URL + '/predictions' + +app = FastAPI() + +class ImageRequest(BaseModel): + prompt: str + width: int = 512 + height: int = 512 + +@app.get('/') +def read_root(): + return FileResponse('index.html') + +@app.get('/ping') +async def ping(): + try: + requests.get(LOCAL_SERVER_URL) + return {'OK'} + except: + return {'ERROR'} + +@app.post('/image') +async def image(req : ImageRequest): + res = requests.post(PREDICT_URL, json={ + "input": { + "prompt": req.prompt, + "width": str(req.width), + "height": str(req.height), + } + }) + return res.json() + +@app.get('/ding.mp3') +def read_root(): + return FileResponse('ding.mp3') diff --git a/server.sh b/server.sh new file mode 100644 index 00000000..b91d095b --- /dev/null +++ b/server.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +IMAGE_NAME="r8.im/stability-ai/stable-diffusion@sha256:06eb78b36068500c616a7f33c15e6fa40404f8e14b5bfad57ebe0c7fe0f6bdf1" + +docker run --name sd -d -p 5000:5000 --gpus all $IMAGE_NAME + +uvicorn main:app --reload \ No newline at end of file diff --git a/shot1.jpeg b/shot1.jpeg new file mode 100644 index 00000000..f532ac44 Binary files /dev/null and b/shot1.jpeg differ