Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,12 @@ from diffusers import StableDiffusionPipeline
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
model_id = "stabilityai/stable-diffusion-2-1"
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def generate(prompt):
|
| 9 |
image = pipe(prompt).images[0]
|
|
@@ -11,4 +16,5 @@ def generate(prompt):
|
|
| 11 |
|
| 12 |
demo = gr.Interface(fn=generate, inputs="text", outputs="image")
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
model_id = "stabilityai/stable-diffusion-2-1"
|
| 6 |
+
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
dtype = torch.float16 if device == "cuda" else torch.float32
|
| 9 |
+
|
| 10 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype)
|
| 11 |
+
pipe = pipe.to(device)
|
| 12 |
|
| 13 |
def generate(prompt):
|
| 14 |
image = pipe(prompt).images[0]
|
|
|
|
| 16 |
|
| 17 |
demo = gr.Interface(fn=generate, inputs="text", outputs="image")
|
| 18 |
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
demo.launch()
|