Spaces:
Runtime error
Runtime error
File size: 3,797 Bytes
8bff7e5 94f661a 8bff7e5 94f661a 8bff7e5 94f661a 8bff7e5 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
from flask import Flask, request, send_file, jsonify, render_template, send_from_directory, Response
import io
import base64
import random
import torch
from models.inference import image_gen
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/image_gen", methods=['POST'])
def gen():
image_path = None
image_bytes = None
prompts_out = request.form['prompts_out']
neg_prompts_out = request.form['neg_prompts_out']
steps_out = int(request.form['steps_out'])
cfg_out = int(request.form['cfg_out'])
num_images_out = int(request.form['num_images_out'])
height_out = int(request.form['height_out'])
width_out = int(request.form['width_out'])
clip_skip_out = int(request.form['clip_skip_out'])
print("---------------------")
print("prompts out ", prompts_out)
print("neg prompt", neg_prompts_out)
print("---------------------")
image = image_gen(prompts_out, neg_prompts_out, steps_out, cfg_out, num_images_out,
height_out, width_out, clip_skip_out)
# print(image)
# print("---------------------")
image_bytes = io.BytesIO()
image.save(image_bytes, format="JPEG", quality=67)
image_bytes = base64.b64encode(image_bytes.getvalue()).decode('utf-8')
print(f"Generated image of size {len(image_bytes)} bytes.")
return render_template('index.html', image_path=image_bytes)
'''
@app.route('/', methods=['POST'])
def myapp():
# prompts_out = request.args["Prompt"]
# neg_prompts_out = request.args["Negative Prompt"]
# steps_out = request.args["Steps"]
# cfg_out = request.args["CFG"]
# num_images_out = request.args["Number of Images"]
# height_out = request.args["Height"]
# width_out = request.args["Width"]
# clip_skip_out = request.args["Clip Skip"]
# img_data = image_gen(prompts_out, neg_prompts_out, steps_out, cfg_out, num_images_out,
# height_out, width_out, clip_skip_out)
# return send_file(img_data, mimetype='image/png')
return "Hello World!"
'''
'''
@app.route('/', methods=['GET', 'POST'])
def index():
image_path = None
image_bytes =None
if request.method == 'POST':
prompts_out = request.form['prompts_out']
neg_prompts_out = request.form['neg_prompts_out']
steps_out = int(request.form['steps_out'])
cfg_out = int(request.form['cfg_out'])
num_images_out = int(request.form['num_images_out'])
height_out = int(request.form['height_out'])
width_out = int(request.form['width_out'])
clip_skip_out = int(request.form['clip_skip_out'])
## seed = random.randrange(1, 100)
print("---------------------")
print("prompts out ", prompts_out)
print("neg prompt", neg_prompts_out)
print("---------------------")
image = image_gen(prompts_out, neg_prompts_out, steps_out, cfg_out, num_images_out,
height_out, width_out, clip_skip_out)
print(image)
print("---------------------")
image_bytes = io.BytesIO()
image.save(image_bytes, format="JPEG", quality=67)
image_bytes = base64.b64encode(image_bytes.getvalue()).decode('utf-8')
print(f"Generated image of size {len(image_bytes)} bytes.")
# img_str = base64.b64encode(image_bytes.getvalue())
# img_obj = "data:image/png;base64," + str(img_str)[2:-1]
# return Response(image_bytes, mimetype="image/jpeg")
# return render_template('result.html',image=img_obj)
return render_template('index.html', image_path=image_bytes)
'''
"""
@app.route('/')
def hello():
return {"test": "Hello world!"}
""" |