-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
71 lines (62 loc) · 1.83 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, request, send_file
import base64
import glob
import io
import os
import torch
from flask_autoindex import AutoIndex
from deepfloyd_if.modules import IFStageI, IFStageII, StableStageIII
from deepfloyd_if.modules.t5 import T5Embedder
from deepfloyd_if.pipelines import dream
app = Flask(__name__)
AutoIndex(app, browse_root='output/')
device="cuda:0"
if_I = None
if_II = None
if_III = None
t5 = None
@app.route('/generate_image', methods=['POST'])
def generate_image():
global if_I, if_II, if_III, t5
stage = int(request.form.get('stage'))
prompt = request.form.get('prompt')
count=1
if if_I is None:
if_I = IFStageI('IF-I-XL-v1.0', device=device)
if_II = IFStageII('IF-II-L-v1.0', device=device)
#if_III = StableStageIII('stable-diffusion-x4-upscaler', device=device)
t5 = T5Embedder(device=device)
result = dream(
t5=t5, if_I=if_I, if_II=if_II, if_III=if_III,
disable_watermark=True,
negative_prompt="stupid, lame",
style_prompt="very profound, deep, inspiring",
prompt=[prompt]*count,
if_I_kwargs={
"guidance_scale": 7.0,
"sample_timestep_respacing": "smart100",
},
if_II_kwargs={
"guidance_scale": 4.0,
"sample_timestep_respacing": "smart50",
},
if_III_kwargs={
"guidance_scale": 9.0,
"noise_level": 20,
"sample_timestep_respacing": "75",
},
)
stage_str = "II"
if stage == 1:
stage_str = "I"
byte_arr = io.BytesIO()
img = result[stage_str][0]
img.save(byte_arr, format='PNG')
byte_arr = byte_arr.getvalue()
return send_file(
io.BytesIO(byte_arr),
mimetype='image/png'
)
if __name__ == '__main__':
port=5000
app.run(host='0.0.0.0', port=port)