Update main.py
Browse files
main.py
CHANGED
|
@@ -1,33 +1,25 @@
|
|
| 1 |
import flask
|
| 2 |
from flask import Flask, request, json, send_file, Response
|
| 3 |
import torch
|
|
|
|
|
|
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
dtype=torch.float32,
|
| 11 |
-
device='cuda',
|
| 12 |
-
is_mega=True,
|
| 13 |
-
is_reusable=True
|
| 14 |
)
|
|
|
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
| 17 |
|
| 18 |
@app.post('/sd')
|
| 19 |
def generate():
|
| 20 |
text = request.json['text']
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
grid_size=2,
|
| 25 |
-
is_seamless=False,
|
| 26 |
-
temperature=1,
|
| 27 |
-
top_k=256,
|
| 28 |
-
supercondition_factor=32,
|
| 29 |
-
is_verbose=False
|
| 30 |
-
)
|
| 31 |
img_io = BytesIO()
|
| 32 |
image.save(img_io)
|
| 33 |
img_io.seek(0)
|
|
|
|
| 1 |
import flask
|
| 2 |
from flask import Flask, request, json, send_file, Response
|
| 3 |
import torch
|
| 4 |
+
from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler
|
| 5 |
+
from random import randrange
|
| 6 |
from io import BytesIO
|
| 7 |
|
| 8 |
+
repo = "Bingsu/my-korean-stable-diffusion-v1-5"
|
| 9 |
+
euler_ancestral_scheduler = EulerAncestralDiscreteScheduler.from_config(repo, subfolder="scheduler")
|
| 10 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 11 |
+
repo, scheduler=euler_ancestral_scheduler, torch_dtype=torch.float16,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
+
pipe.to("cuda")
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
|
| 17 |
@app.post('/sd')
|
| 18 |
def generate():
|
| 19 |
text = request.json['text']
|
| 20 |
+
seed = randrange(1, 9999999999)
|
| 21 |
+
generator = torch.Generator('cuda').manual_seed(seed)
|
| 22 |
+
image = pipe(text, num_inference_steps=25, generator=generator).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
img_io = BytesIO()
|
| 24 |
image.save(img_io)
|
| 25 |
img_io.seek(0)
|