File size: 932 Bytes
964938c |
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 |
@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)})
|