|
@app.route('/generate_image', methods=['POST']) |
|
def generate_image(): |
|
try: |
|
|
|
text_description = request.json['text_description'] |
|
|
|
|
|
output = model.generate_images(text_description) |
|
|
|
|
|
image_data = requests.get(output[0]["image"]).content |
|
|
|
|
|
save_image = request.json.get('save_image', False) |
|
|
|
if save_image: |
|
|
|
with open("generated_image.jpg", "wb") as img_file: |
|
img_file.write(image_data) |
|
return jsonify({'message': 'Image generated and saved successfully'}) |
|
else: |
|
|
|
return jsonify({'image_data': image_data}) |
|
except Exception as e: |
|
return jsonify({'error': str(e)}) |
|
|