From f96633219304445ff9da8e38876cf65b77163ed2 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Wed, 4 Jan 2023 18:25:00 -0600 Subject: [PATCH] test server --- api/.gitignore | 2 ++ api/serve.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 api/.gitignore create mode 100644 api/serve.py diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 00000000..92afa22f --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +venv/ diff --git a/api/serve.py b/api/serve.py new file mode 100644 index 00000000..de00f4e6 --- /dev/null +++ b/api/serve.py @@ -0,0 +1,24 @@ +from diffusers import OnnxStableDiffusionPipeline +from flask import Flask + +max_height = 512 +max_width = 512 + +app = Flask(__name__) +pipe = OnnxStableDiffusionPipeline.from_pretrained("./stable_diffusion_onnx", provider="DmlExecutionProvider", safety_checker=None) + + +@app.route('/') +def hello(): + return 'Hello, World!' + +@app.route('/txt2img') +def txt2img(): + height = request.args.get('height', max_height) + width = request.args.get('width', max_width) + prompt = request.args.get('prompt', "a photo of an astronaut eating a hamburger") + steps = 50 + cfg = 8 + + image = pipe(prompt, height, width, num_inference_steps=steps, guidance_scale=cfg).images[0] + image.save("astronaut_rides_horse.png")