Yaron Koresh commited on
Commit
ae40afc
·
verified ·
1 Parent(s): 35ac61a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -66,12 +66,16 @@ def translate(text,lang):
66
  print(ret)
67
  return ret
68
 
 
 
 
 
69
  def generate_random_string(length):
70
  characters = string.ascii_letters + string.digits
71
  return ''.join(random.choice(characters) for _ in range(length))
72
 
73
  @spaces.GPU(duration=40)
74
- def Piper(name,posi,neg):
75
  global step
76
 
77
  print("starting piper")
@@ -81,7 +85,9 @@ def Piper(name,posi,neg):
81
  height=512,
82
  width=512,
83
  num_inference_steps=step,
84
- guidance_scale=1
 
 
85
  )
86
 
87
  export_to_gif(out.frames[0],name)
@@ -173,8 +179,8 @@ def main():
173
  repo = "ByteDance/SDXL-Lightning"
174
  ckpt = f"sdxl_lightning_{step}step_unet.safetensors"
175
 
176
- unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
177
- unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
178
 
179
  repo = "ByteDance/AnimateDiff-Lightning"
180
  ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
@@ -182,7 +188,7 @@ def main():
182
  adapter = MotionAdapter().to(device, dtype)
183
  adapter.load_state_dict(load_file(hf_hub_download(repo ,ckpt), device=device))
184
 
185
- pipe = AnimateDiffPipeline.from_pretrained(base, motion_adapter=adapter, unet=unet, torch_dtype=dtype, variant="fp16").to(device=device, dtype=dtype)
186
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
187
 
188
  mp.set_start_method("spawn", force=True)
 
66
  print(ret)
67
  return ret
68
 
69
+ progress((0, step))
70
+ def progress_callback(i, t, z):
71
+ progress((i+1, step))
72
+
73
  def generate_random_string(length):
74
  characters = string.ascii_letters + string.digits
75
  return ''.join(random.choice(characters) for _ in range(length))
76
 
77
  @spaces.GPU(duration=40)
78
+ def Piper(name,posi):
79
  global step
80
 
81
  print("starting piper")
 
85
  height=512,
86
  width=512,
87
  num_inference_steps=step,
88
+ guidance_scale=1,
89
+ callback=progress_callback,
90
+ callback_step=1
91
  )
92
 
93
  export_to_gif(out.frames[0],name)
 
179
  repo = "ByteDance/SDXL-Lightning"
180
  ckpt = f"sdxl_lightning_{step}step_unet.safetensors"
181
 
182
+ #unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(device, dtype)
183
+ #unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device=device))
184
 
185
  repo = "ByteDance/AnimateDiff-Lightning"
186
  ckpt = f"animatediff_lightning_{step}step_diffusers.safetensors"
 
188
  adapter = MotionAdapter().to(device, dtype)
189
  adapter.load_state_dict(load_file(hf_hub_download(repo ,ckpt), device=device))
190
 
191
+ pipe = AnimateDiffPipeline.from_pretrained(base, motion_adapter=adapter, torch_dtype=dtype, variant="fp16").to(device)
192
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", beta_schedule="linear")
193
 
194
  mp.set_start_method("spawn", force=True)