feat(api): add endpoints to serve GUI bundle
This commit is contained in:
parent
3c0d854834
commit
db06754c90
|
@ -48,9 +48,13 @@ max_height = 512
|
||||||
max_width = 512
|
max_width = 512
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
bundle_path = environ.get('ONNX_WEB_BUNDLE_PATH', path.join('..', '..', 'gui', 'out'))
|
# paths used for Flask files must have ../..
|
||||||
|
# paths used for fopen only need ../
|
||||||
|
bundle_path = environ.get('ONNX_WEB_BUNDLE_PATH',
|
||||||
|
path.join('..', '..', 'gui', 'out'))
|
||||||
model_path = environ.get('ONNX_WEB_MODEL_PATH', path.join('..', 'models'))
|
model_path = environ.get('ONNX_WEB_MODEL_PATH', path.join('..', 'models'))
|
||||||
output_path = environ.get('ONNX_WEB_OUTPUT_PATH', path.join('..', 'outputs'))
|
output_path = environ.get('ONNX_WEB_OUTPUT_PATH',
|
||||||
|
path.join('..', '..', 'outputs'))
|
||||||
params_path = environ.get('ONNX_WEB_PARAMS_PATH', 'params.json')
|
params_path = environ.get('ONNX_WEB_PARAMS_PATH', 'params.json')
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,6 +154,10 @@ def json_with_cors(data, origin='*'):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def serve_bundle_file(filename='index.html'):
|
||||||
|
return send_from_directory(bundle_path, filename)
|
||||||
|
|
||||||
|
|
||||||
def make_output_path(mode: str, seed: int, params: Tuple[Union[str, int, float]]):
|
def make_output_path(mode: str, seed: int, params: Tuple[Union[str, int, float]]):
|
||||||
sha = sha256()
|
sha = sha256()
|
||||||
sha.update(mode.encode('utf-8'))
|
sha.update(mode.encode('utf-8'))
|
||||||
|
@ -315,20 +323,15 @@ executor = Executor(app)
|
||||||
|
|
||||||
# routes
|
# routes
|
||||||
|
|
||||||
def serve_file(filename = 'index.html'):
|
|
||||||
file = path.join(bundle_path, filename)
|
|
||||||
print('index', file)
|
|
||||||
return send_file(file)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return serve_file()
|
return serve_bundle_file()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<path:filename>')
|
@app.route('/<path:filename>')
|
||||||
def index_path(filename):
|
def index_path(filename):
|
||||||
return serve_file(filename)
|
return serve_bundle_file(filename)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api')
|
@app.route('/api')
|
||||||
|
@ -378,7 +381,7 @@ def img2img():
|
||||||
print("img2img output: %s" % (output_full))
|
print("img2img output: %s" % (output_full))
|
||||||
|
|
||||||
executor.submit_stored(output_file, run_img2img_pipeline, model, provider,
|
executor.submit_stored(output_file, run_img2img_pipeline, model, provider,
|
||||||
scheduler, prompt, negative_prompt, cfg, steps, seed, output_full, strength, input_image)
|
scheduler, prompt, negative_prompt, cfg, steps, seed, output_full, strength, input_image)
|
||||||
|
|
||||||
return json_with_cors({
|
return json_with_cors({
|
||||||
'output': output_file,
|
'output': output_file,
|
||||||
|
@ -407,7 +410,7 @@ def txt2img():
|
||||||
print("txt2img output: %s" % (output_full))
|
print("txt2img output: %s" % (output_full))
|
||||||
|
|
||||||
executor.submit_stored(output_file, run_txt2img_pipeline, model,
|
executor.submit_stored(output_file, run_txt2img_pipeline, model,
|
||||||
provider, scheduler, prompt, negative_prompt, cfg, steps, seed, output_full, height, width)
|
provider, scheduler, prompt, negative_prompt, cfg, steps, seed, output_full, height, width)
|
||||||
|
|
||||||
return json_with_cors({
|
return json_with_cors({
|
||||||
'output': output_file,
|
'output': output_file,
|
||||||
|
@ -444,7 +447,7 @@ def inpaint():
|
||||||
print("inpaint output: %s" % output_full)
|
print("inpaint output: %s" % output_full)
|
||||||
|
|
||||||
executor.submit_stored(output_file, run_inpaint_pipeline, model, provider, scheduler, prompt, negative_prompt,
|
executor.submit_stored(output_file, run_inpaint_pipeline, model, provider, scheduler, prompt, negative_prompt,
|
||||||
cfg, steps, seed, output_full, height, width, source_image, mask_image)
|
cfg, steps, seed, output_full, height, width, source_image, mask_image)
|
||||||
|
|
||||||
return json_with_cors({
|
return json_with_cors({
|
||||||
'output': output_file,
|
'output': output_file,
|
||||||
|
@ -474,4 +477,4 @@ def ready():
|
||||||
|
|
||||||
@app.route('/api/output/<path:filename>')
|
@app.route('/api/output/<path:filename>')
|
||||||
def output(filename: str):
|
def output(filename: str):
|
||||||
return send_from_directory(path.join('..', output_path), filename, as_attachment=False)
|
return send_from_directory(output_path, filename, as_attachment=False)
|
||||||
|
|
Loading…
Reference in New Issue