from flask import Flask, request | |
from diffusers import StableDiffusionPipeline | |
import torch | |
app = Flask(__name__) | |
model_id = "runwayml/stable-diffusion-v1-5" | |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
pipe = pipe.to("cuda") | |
def dummy(images, **kwargs): | |
return images, False | |
pipe.safety_checker = dummy | |
def generate_image(): | |
prompt = request.args.get('prompt') | |
image = pipe(prompt).images[0] | |
# do something with the generated image | |
return image | |
if __name__ == '__main__': | |
app.run() |