| # -*- coding: utf-8 -*- | |
| """StableDiffusion.ipynb | |
| Automatically generated by Colaboratory. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1O7cgP1KO74ZqtTiW_ps2xZgEzwh-LuLi | |
| """ | |
| !pip install diffusers transformers accelerate torch | |
| !pip install gradio | |
| import gradio as gr | |
| from diffusers import DiffusionPipeline | |
| import torch | |
| pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16") | |
| pipe.to("cuda") | |
| def generate(prompt): | |
| image = pipe(prompt).images[0] | |
| return image | |
| gr.Interface(fn=generate, inputs="text", outputs="image").launch(debug=True) |