Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import
|
2 |
from diffusers import StableDiffusionPipeline
|
3 |
import torch
|
4 |
from fastapi import FastAPI, Response
|
@@ -26,13 +26,18 @@ pipe.safety_checker = dummy
|
|
26 |
|
27 |
@app.route('/')
|
28 |
def hello():
|
29 |
-
return "Hello
|
|
|
30 |
|
31 |
@app.route('/gen')
|
32 |
def generate_image():
|
33 |
prompt = request.args.get('prompt')
|
34 |
image = pipe(prompt).images[0]
|
|
|
|
|
|
|
35 |
# do something with the generated image
|
36 |
image_data = image.tobytes().hex()
|
|
|
37 |
|
38 |
-
return {'image_data': image_data}
|
|
|
1 |
+
from flask import url_for
|
2 |
from diffusers import StableDiffusionPipeline
|
3 |
import torch
|
4 |
from fastapi import FastAPI, Response
|
|
|
26 |
|
27 |
@app.route('/')
|
28 |
def hello():
|
29 |
+
return {"Hello": Artist}
|
30 |
+
|
31 |
|
32 |
@app.route('/gen')
|
33 |
def generate_image():
|
34 |
prompt = request.args.get('prompt')
|
35 |
image = pipe(prompt).images[0]
|
36 |
+
# Save the image
|
37 |
+
image.save('static/image.png')
|
38 |
+
|
39 |
# do something with the generated image
|
40 |
image_data = image.tobytes().hex()
|
41 |
+
image_url = url_for('static', filename='image.png')
|
42 |
|
43 |
+
return {'image_data': image_data, 'image_url': image_url}
|