FENST4R commited on
Commit
2179156
·
verified ·
1 Parent(s): 8418c45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -3,7 +3,12 @@ from diffusers import StableDiffusionPipeline
3
  import torch
4
 
5
  model_id = "stabilityai/stable-diffusion-2-1"
6
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
 
 
 
 
 
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
- demo.launch()
 
 
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()