Listart / generate_image
Zeroxdesignart's picture
Create generate_image
964938c
raw
history blame
932 Bytes
@app.route('/generate_image', methods=['POST'])
def generate_image():
try:
# Get text input from the request
text_description = request.json['text_description']
# Generate an image from the text description
output = model.generate_images(text_description)
# Get the image data
image_data = requests.get(output[0]["image"]).content
# Check if the user wants to save the image
save_image = request.json.get('save_image', False)
if save_image:
# Save the image to a file
with open("generated_image.jpg", "wb") as img_file:
img_file.write(image_data)
return jsonify({'message': 'Image generated and saved successfully'})
else:
# Return the image as a response
return jsonify({'image_data': image_data})
except Exception as e:
return jsonify({'error': str(e)})