Upload stablediffusion.py
Browse files- stablediffusion.py +24 -0
stablediffusion.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""StableDiffusion.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1O7cgP1KO74ZqtTiW_ps2xZgEzwh-LuLi
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
!pip install diffusers transformers accelerate torch
|
| 11 |
+
|
| 12 |
+
!pip install gradio
|
| 13 |
+
import gradio as gr
|
| 14 |
+
from diffusers import DiffusionPipeline
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 18 |
+
pipe.to("cuda")
|
| 19 |
+
|
| 20 |
+
def generate(prompt):
|
| 21 |
+
image = pipe(prompt).images[0]
|
| 22 |
+
return image
|
| 23 |
+
|
| 24 |
+
gr.Interface(fn=generate, inputs="text", outputs="image").launch(debug=True)
|