image_test / api.py
Ma7mouD-7's picture
Upload 2 files
19c33ef
from flask import Flask, request, jsonify, render_template_string
from model import generate_image
app = Flask(__name__)
# @app.route("/")
# def api_generate_image():
# # Generate the image using the model
# image = generate_image("Hello, world!")
# # Embed the image in an HTML page
# html = """
# <html>
# <body>
# <h1>Generated Image</h1>
# <img src="data:image/jpeg;base64,{{ image }}" />
# </body>
# </html>
# """
# return render_template_string(html, image=image)
@app.route("/generate_image", methods=["POST"])
def api_generate_image():
# Get the input text from the request
text = request.json["text"]
# Generate the image using the model
image = generate_image(text)
# Return the generated image as the response
response = {"image": image}
return jsonify(response)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)