Zeroxdesignart
commited on
Commit
•
964938c
1
Parent(s):
fc0fa6f
Create generate_image
Browse files- generate_image +25 -0
generate_image
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@app.route('/generate_image', methods=['POST'])
|
2 |
+
def generate_image():
|
3 |
+
try:
|
4 |
+
# Get text input from the request
|
5 |
+
text_description = request.json['text_description']
|
6 |
+
|
7 |
+
# Generate an image from the text description
|
8 |
+
output = model.generate_images(text_description)
|
9 |
+
|
10 |
+
# Get the image data
|
11 |
+
image_data = requests.get(output[0]["image"]).content
|
12 |
+
|
13 |
+
# Check if the user wants to save the image
|
14 |
+
save_image = request.json.get('save_image', False)
|
15 |
+
|
16 |
+
if save_image:
|
17 |
+
# Save the image to a file
|
18 |
+
with open("generated_image.jpg", "wb") as img_file:
|
19 |
+
img_file.write(image_data)
|
20 |
+
return jsonify({'message': 'Image generated and saved successfully'})
|
21 |
+
else:
|
22 |
+
# Return the image as a response
|
23 |
+
return jsonify({'image_data': image_data})
|
24 |
+
except Exception as e:
|
25 |
+
return jsonify({'error': str(e)})
|