-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
65 lines (56 loc) · 2.04 KB
/
Copy pathapp.py
File metadata and controls
65 lines (56 loc) · 2.04 KB
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
from flask import Flask, render_template, request, jsonify
import json
import requests
import io
from io import BytesIO
import base64
from PIL import Image, PngImagePlugin
import gzip
from translate import Translator
app = Flask(__name__)
def generate_image(prompt,width,height):
url = "http://127.0.0.1:7860"
payload = {
"prompt": prompt,
"negative_prompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation",
"seed": -1,
"subseed": -1,
"subseed_strength": 0,
"seed_resize_from_h": -1,
"seed_resize_from_w": -1,
"batch_size": 1,
"n_iter": 1,
"steps": 25,
"cfg_scale": 7,
"width": width,
"height": height,
"restore_faces": "false",
"tiling": "false",
"do_not_save_samples": "false",
"do_not_save_grid": "false",
"eta": 0,
"s_churn": 0,
"s_tmax": 0,
"s_tmin": 0,
"s_noise": 1,
"override_settings": {"sd_model_checkpoint": "realisticVisionV20_v20.safetensors [c0d1994c73]"},
"override_settings_restore_afterwards": "true",
"sampler_index": "DPM++ SDE Karras",
}
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()
base64_str = r['images'][0].split(",", 1)[0]
return base64_str
@app.route('/')
def home():
return render_template('index.html')
@app.route('/', methods=['POST'])
def generate():
prompt = request.json['prompt']
width = request.json['width']
height = request.json['height']
print("start to generate_image")
image_data = generate_image(prompt,width,height)
return jsonify({"image": image_data})
if __name__ == '__main__':
app.run()