Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
from
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
-
# Load Stable Diffusion model
|
7 |
-
|
|
|
8 |
|
9 |
@app.route('/generate-image', methods=['POST'])
|
10 |
def generate_image():
|
@@ -12,19 +14,20 @@ def generate_image():
|
|
12 |
if not description:
|
13 |
return jsonify({'error': 'No description provided'}), 400
|
14 |
|
15 |
-
# Generate image from description
|
16 |
-
image =
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
|
21 |
-
return jsonify({'image_url':
|
22 |
|
23 |
def save_image(image):
|
24 |
-
# Save
|
25 |
-
image_path = '/path/to/save/
|
26 |
-
image
|
27 |
return image_path
|
28 |
|
29 |
if __name__ == '__main__':
|
30 |
app.run(debug=True)
|
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import torch
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
+
# Load Stable Diffusion model from Hugging Face
|
8 |
+
model_id = "CompVis/stable-diffusion-v-1-4-original"
|
9 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
|
10 |
|
11 |
@app.route('/generate-image', methods=['POST'])
|
12 |
def generate_image():
|
|
|
14 |
if not description:
|
15 |
return jsonify({'error': 'No description provided'}), 400
|
16 |
|
17 |
+
# Generate image from description using Stable Diffusion
|
18 |
+
image = pipe(description).images[0]
|
19 |
|
20 |
+
# Save or serve the image
|
21 |
+
image_path = save_image(image) # Implement a function to save or serve the image
|
22 |
|
23 |
+
return jsonify({'image_url': image_path})
|
24 |
|
25 |
def save_image(image):
|
26 |
+
# Save the generated image to a path
|
27 |
+
image_path = '/path/to/save/generated_image.png'
|
28 |
+
image.save(image_path)
|
29 |
return image_path
|
30 |
|
31 |
if __name__ == '__main__':
|
32 |
app.run(debug=True)
|
33 |
+
|