-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (49 loc) · 1.34 KB
/
main.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
import chromedriver_autoinstaller
from res.scripts.get_jwt import get_jwt
from res.scripts.generate_images import get_image_batch
from res.SaveConfig import SaveConfig
from flask import Flask, request, jsonify
#get email and password
email = ""
password = ""
with open('account.txt', 'r') as file:
email = file.readline().replace('\n', '')
password = file.readline().replace('\n', '')
#get jtw
chromedriver_autoinstaller.install()
_jwt = get_jwt(email, password)
print("Got jwt:", _jwt)
#prepare saveconfig
save_config = SaveConfig(
save_dir="output/images",
save_name="image",
force_mkdir=True,
additional_return_mode=True,
separator="-"
)
#run flask
app = Flask("lol")
@app.route('/sdapi/v1/options')
def apiOptions():
return 'ok'
@app.route('/sdapi/v1/sd-models')
def apiModels():
return 'ok'
@app.route('/sdapi/v1/txt2img', methods=['POST'])
def text2Image() :
data = request.get_json()
prompt = data['prompt']
negative_prompt = data["negative_prompt"]
width = data["width"]
height = data["height"]
images = get_image_batch(
prompt=prompt,
negative_prompt=negative_prompt,
size=(width, height),
_n=1,
__jwt=_jwt,
_saveConfig=save_config
)
data = {"format" : 'png', "images" : images}
return jsonify(data)
app.run(debug=False)