UdacityNoob commited on
Commit
5a33599
β€’
1 Parent(s): 6ca233b

Update requirements typo, update app.py

Browse files
Files changed (2) hide show
  1. app.py +7 -4
  2. requirements.txt +1 -1
app.py CHANGED
@@ -12,14 +12,17 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
12
  device_name = torch.cuda.get_device_name(0)
13
 
14
  # setup pipeline
15
- pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=TOKEN_KEY)
 
 
 
16
  pipe = pipe.to(device)
17
 
18
  # define gradio function
19
- def generate(prompt:str, seed:int, guidance:float):
20
  generator = torch.Generator(device).manual_seed(int(seed))
21
  with autocast(device):
22
- image = pipe(prompt=prompt, generator=generator, guidance_scale=guidance, steps=50).images[0]
23
  return image
24
 
25
  if device == "cuda":
@@ -27,7 +30,7 @@ if device == "cuda":
27
  # create the gradio UI
28
  demo = gr.Interface(
29
  fn=generate,
30
- inputs=[gr.Textbox(placeholder="castle on a mountain"), gr.Number(value=123456), gr.Slider(0,10)],
31
  outputs="image",
32
  allow_flagging="never",
33
  )
 
12
  device_name = torch.cuda.get_device_name(0)
13
 
14
  # setup pipeline
15
+ if device == "cuda":
16
+ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=TOKEN_KEY)
17
+ else:
18
+ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=TOKEN_KEY)
19
  pipe = pipe.to(device)
20
 
21
  # define gradio function
22
+ def generate(prompt:str, seed:int, guidance:float, steps:int):
23
  generator = torch.Generator(device).manual_seed(int(seed))
24
  with autocast(device):
25
+ image = pipe(prompt=prompt, generator=generator, guidance_scale=guidance, num_inference_steps=steps).images[0]
26
  return image
27
 
28
  if device == "cuda":
 
30
  # create the gradio UI
31
  demo = gr.Interface(
32
  fn=generate,
33
+ inputs=[gr.Textbox(placeholder="castle on a mountain"), gr.Number(value=123456), gr.Slider(0,10), gr.Number(value=50)],
34
  outputs="image",
35
  allow_flagging="never",
36
  )
requirements.txt CHANGED
@@ -3,5 +3,5 @@ scipy
3
  ftfy
4
  torch>=1.10.0
5
  transformers
6
- diffuser>=0.3.0
7
  gradio>=3.4
 
3
  ftfy
4
  torch>=1.10.0
5
  transformers
6
+ diffusers>=0.4.0
7
  gradio>=3.4