Spaces:
Runtime error
Runtime error
Upload 23 files
Browse files- Dockerfile +0 -2
- README-ja.md +31 -0
- requirements.txt +2 -0
- server/config.py +3 -3
- server/main.py +10 -3
- server/requirements.txt +1 -1
- start.sh +1 -1
- view/build/asset-manifest.json +15 -0
- view/build/favicon.ico +0 -0
- view/build/images/white.jpg +0 -0
- view/build/index.html +1 -0
- view/build/manifest.json +25 -0
- view/build/robots.txt +3 -0
Dockerfile
CHANGED
@@ -57,8 +57,6 @@ RUN pyenv install $PYTHON_VERSION && \
|
|
57 |
COPY --chown=user:user . .
|
58 |
# change dir since pip needs to seed whl folder
|
59 |
RUN cd server && pip install --no-cache-dir --upgrade -r requirements.txt
|
60 |
-
RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
|
61 |
-
pip install git+https://$(cat /run/secrets/GITHUB_TOKEN)@github.com/cumulo-autumn/StreamDiffusion.git
|
62 |
RUN python -m streamdiffusion.tools.install-tensorrt
|
63 |
|
64 |
COPY --from=frontend /app/build ./view/build
|
|
|
57 |
COPY --chown=user:user . .
|
58 |
# change dir since pip needs to seed whl folder
|
59 |
RUN cd server && pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
|
|
60 |
RUN python -m streamdiffusion.tools.install-tensorrt
|
61 |
|
62 |
COPY --from=frontend /app/build ./view/build
|
README-ja.md
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Txt2Img Example
|
2 |
+
|
3 |
+
[English](./README.md) | [日本語](./README-ja.md)
|
4 |
+
|
5 |
+
<p align="center">
|
6 |
+
<img src="../../assets/demo_01.gif" width=80%>
|
7 |
+
</p>
|
8 |
+
|
9 |
+
StreamDiffusion を用いた GUI を提供します。
|
10 |
+
入力プロンプトを変更すると、テキストから 4x4 の画像をリアルタイムに生成することができます。
|
11 |
+
|
12 |
+
## 使用方法
|
13 |
+
|
14 |
+
以下のコマンドを順番に実行してください。
|
15 |
+
|
16 |
+
```bash
|
17 |
+
pip install -r requirements.txt
|
18 |
+
cd view
|
19 |
+
npm i
|
20 |
+
npm start &
|
21 |
+
cd ../server
|
22 |
+
python main.py
|
23 |
+
```
|
24 |
+
|
25 |
+
# 謝辞
|
26 |
+
|
27 |
+
この GitHubリポジトリ にある動画と画像のデモは、[kohakuV2](https://civitai.com/models/136268/kohaku-v2)と[SD-Turbo](https://arxiv.org/abs/2311.17042)を使用して生成されました。
|
28 |
+
|
29 |
+
KohakuV2 モデルを提供していただいたKohaku BlueLeaf 様 ([@KBlueleaf](https://twitter.com/KBlueleaf))、[SD-Turbo](https://arxiv.org/abs/2311.17042)を提供していただいた[Stability AI](https://ja.stability.ai/)様に心より感謝いたします。
|
30 |
+
|
31 |
+
KohakuV2 モデルは [Civitai](https://civitai.com/models/136268/kohaku-v2) と [Hugging Face](https://huggingface.co/stabilityai/sd-turbo) からダウンロードでき、[SD-Turbo](https://arxiv.org/abs/2311.17042) は Hugging Faceで使用可能です。
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
uvicorn>=0.24.0
|
2 |
+
fastapi>=0.104.1
|
server/config.py
CHANGED
@@ -26,9 +26,9 @@ class Config:
|
|
26 |
####################################################################
|
27 |
mode: Literal["txt2img", "img2img"] = "txt2img"
|
28 |
# SD1.x variant model
|
29 |
-
|
30 |
# LCM-LORA model
|
31 |
-
lcm_lora_id: str =
|
32 |
# TinyVAE model
|
33 |
vae_id: str = "madebyollin/taesd"
|
34 |
# Device to use
|
@@ -36,7 +36,7 @@ class Config:
|
|
36 |
# Data type
|
37 |
dtype: torch.dtype = torch.float16
|
38 |
# acceleration
|
39 |
-
acceleration: Literal["none", "xformers", "
|
40 |
|
41 |
####################################################################
|
42 |
# Inference configuration
|
|
|
26 |
####################################################################
|
27 |
mode: Literal["txt2img", "img2img"] = "txt2img"
|
28 |
# SD1.x variant model
|
29 |
+
model_id_or_path: str = "KBlueLeaf/kohaku-v2.1"
|
30 |
# LCM-LORA model
|
31 |
+
lcm_lora_id: str = "latent-consistency/lcm-lora-sdv1-5"
|
32 |
# TinyVAE model
|
33 |
vae_id: str = "madebyollin/taesd"
|
34 |
# Device to use
|
|
|
36 |
# Data type
|
37 |
dtype: torch.dtype = torch.float16
|
38 |
# acceleration
|
39 |
+
acceleration: Literal["none", "xformers", "tensorrt"] = "xformers"
|
40 |
|
41 |
####################################################################
|
42 |
# Inference configuration
|
server/main.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import asyncio
|
2 |
import base64
|
3 |
import logging
|
@@ -12,8 +14,10 @@ from fastapi.staticfiles import StaticFiles
|
|
12 |
|
13 |
from PIL import Image
|
14 |
from pydantic import BaseModel
|
15 |
-
from wrapper import StreamDiffusionWrapper
|
16 |
|
|
|
|
|
|
|
17 |
|
18 |
logger = logging.getLogger("uvicorn")
|
19 |
PROJECT_DIR = Path(__file__).parent.parent
|
@@ -56,7 +60,7 @@ class Api:
|
|
56 |
self.config = config
|
57 |
self.stream_diffusion = StreamDiffusionWrapper(
|
58 |
mode=config.mode,
|
59 |
-
|
60 |
lcm_lora_id=config.lcm_lora_id,
|
61 |
vae_id=config.vae_id,
|
62 |
device=config.device,
|
@@ -65,6 +69,7 @@ class Api:
|
|
65 |
t_index_list=config.t_index_list,
|
66 |
warmup=config.warmup,
|
67 |
use_safety_checker=config.use_safety_checker,
|
|
|
68 |
)
|
69 |
self.app = FastAPI()
|
70 |
self.app.add_api_route(
|
@@ -103,7 +108,9 @@ class Api:
|
|
103 |
"""
|
104 |
async with self._predict_lock:
|
105 |
return PredictResponseModel(
|
106 |
-
base64_image=self._pil_to_base64(
|
|
|
|
|
107 |
)
|
108 |
|
109 |
def _pil_to_base64(self, image: Image.Image, format: str = "JPEG") -> bytes:
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
import asyncio
|
4 |
import base64
|
5 |
import logging
|
|
|
14 |
|
15 |
from PIL import Image
|
16 |
from pydantic import BaseModel
|
|
|
17 |
|
18 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
19 |
+
|
20 |
+
from utils.wrapper import StreamDiffusionWrapper
|
21 |
|
22 |
logger = logging.getLogger("uvicorn")
|
23 |
PROJECT_DIR = Path(__file__).parent.parent
|
|
|
60 |
self.config = config
|
61 |
self.stream_diffusion = StreamDiffusionWrapper(
|
62 |
mode=config.mode,
|
63 |
+
model_id_or_path=config.model_id_or_path,
|
64 |
lcm_lora_id=config.lcm_lora_id,
|
65 |
vae_id=config.vae_id,
|
66 |
device=config.device,
|
|
|
69 |
t_index_list=config.t_index_list,
|
70 |
warmup=config.warmup,
|
71 |
use_safety_checker=config.use_safety_checker,
|
72 |
+
cfg_type="none",
|
73 |
)
|
74 |
self.app = FastAPI()
|
75 |
self.app.add_api_route(
|
|
|
108 |
"""
|
109 |
async with self._predict_lock:
|
110 |
return PredictResponseModel(
|
111 |
+
base64_image=self._pil_to_base64(
|
112 |
+
self.stream_diffusion(prompt=inp.prompt)
|
113 |
+
)
|
114 |
)
|
115 |
|
116 |
def _pil_to_base64(self, image: Image.Image, format: str = "JPEG") -> bytes:
|
server/requirements.txt
CHANGED
@@ -2,7 +2,7 @@ xformers
|
|
2 |
uvicorn[standard]==0.24.0.post1
|
3 |
fastapi==0.104
|
4 |
accelerate
|
5 |
-
|
6 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
7 |
torch
|
8 |
torchvision
|
|
|
2 |
uvicorn[standard]==0.24.0.post1
|
3 |
fastapi==0.104
|
4 |
accelerate
|
5 |
+
git+https://github.com/cumulo-autumn/StreamDiffusion.git@main#egg="streamdiffusion[tensorrt]"
|
6 |
--extra-index-url https://download.pytorch.org/whl/cu121
|
7 |
torch
|
8 |
torchvision
|
start.sh
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
#!/bin/bash
|
2 |
pip install -r requirements.txt
|
3 |
-
cd view && npm run build && cd ..
|
4 |
cd server && python3 main.py
|
|
|
1 |
#!/bin/bash
|
2 |
pip install -r requirements.txt
|
3 |
+
cd view && npm install && npm run build && cd ..
|
4 |
cd server && python3 main.py
|
view/build/asset-manifest.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"files": {
|
3 |
+
"main.css": "/static/css/main.ee59dfc2.css",
|
4 |
+
"main.js": "/static/js/main.d05767f4.js",
|
5 |
+
"static/js/787.0fef8e45.chunk.js": "/static/js/787.0fef8e45.chunk.js",
|
6 |
+
"index.html": "/index.html",
|
7 |
+
"main.ee59dfc2.css.map": "/static/css/main.ee59dfc2.css.map",
|
8 |
+
"main.d05767f4.js.map": "/static/js/main.d05767f4.js.map",
|
9 |
+
"787.0fef8e45.chunk.js.map": "/static/js/787.0fef8e45.chunk.js.map"
|
10 |
+
},
|
11 |
+
"entrypoints": [
|
12 |
+
"static/css/main.ee59dfc2.css",
|
13 |
+
"static/js/main.d05767f4.js"
|
14 |
+
]
|
15 |
+
}
|
view/build/favicon.ico
ADDED
|
view/build/images/white.jpg
ADDED
![]() |
view/build/index.html
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Kanit:wght@500&display=swap" rel="stylesheet"><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.d05767f4.js"></script><link href="/static/css/main.ee59dfc2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
view/build/manifest.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"short_name": "React App",
|
3 |
+
"name": "Create React App Sample",
|
4 |
+
"icons": [
|
5 |
+
{
|
6 |
+
"src": "favicon.ico",
|
7 |
+
"sizes": "128x128 64x64 32x32 24x24 16x16",
|
8 |
+
"type": "image/x-icon"
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"src": "logo192.png",
|
12 |
+
"type": "image/png",
|
13 |
+
"sizes": "192x192"
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"src": "logo512.png",
|
17 |
+
"type": "image/png",
|
18 |
+
"sizes": "512x512"
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"start_url": ".",
|
22 |
+
"display": "standalone",
|
23 |
+
"theme_color": "#000000",
|
24 |
+
"background_color": "#ffffff"
|
25 |
+
}
|
view/build/robots.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# https://www.robotstxt.org/robotstxt.html
|
2 |
+
User-agent: *
|
3 |
+
Disallow:
|