YiftachEde commited on
Commit
f6e0da0
·
verified ·
1 Parent(s): d7e594b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -322,23 +322,22 @@ class ShapERenderer:
322
  guidance_scale = float(guidance_scale)
323
 
324
  with torch.amp.autocast('cuda'): # Use automatic mixed precision
325
- # spaces duration is 20 seconds, so we need to be careful here
326
-
327
  latents = sample_latents(
328
  batch_size=batch_size,
329
  model=self.model,
330
  diffusion=self.diffusion,
331
  guidance_scale=guidance_scale,
332
  model_kwargs=dict(texts=[prompt] * batch_size),
333
- progress=True,
334
- clip_denoised=True,
335
- use_fp16=True,
336
- use_karras=True,
337
- karras_steps=num_steps,
338
- sigma_min=1e-3,
339
- sigma_max=160,
340
- s_churn=0,
341
- )
342
 
343
  # Render the 6 views we need with specific viewing angles
344
  size = 320 # Size of each rendered image
@@ -539,6 +538,7 @@ def create_demo():
539
  )
540
 
541
  # Set up event handlers
 
542
  def generate(prompt, guidance_scale, num_steps):
543
  try:
544
  torch.cuda.empty_cache() # Clear GPU memory before starting
@@ -551,7 +551,7 @@ def create_demo():
551
  print(error_msg)
552
  return None, error_msg
553
 
554
- @spaces.GPU(duration=20) # Reduced duration to 20 seconds
555
  def refine(input_image, prompt, steps, guidance_scale):
556
  try:
557
  torch.cuda.empty_cache() # Clear GPU memory before starting
 
322
  guidance_scale = float(guidance_scale)
323
 
324
  with torch.amp.autocast('cuda'): # Use automatic mixed precision
325
+ # Generate latents directly without nested spaces.GPU context
 
326
  latents = sample_latents(
327
  batch_size=batch_size,
328
  model=self.model,
329
  diffusion=self.diffusion,
330
  guidance_scale=guidance_scale,
331
  model_kwargs=dict(texts=[prompt] * batch_size),
332
+ progress=True,
333
+ clip_denoised=True,
334
+ use_fp16=True,
335
+ use_karras=True,
336
+ karras_steps=num_steps,
337
+ sigma_min=1e-3,
338
+ sigma_max=160,
339
+ s_churn=0,
340
+ )
341
 
342
  # Render the 6 views we need with specific viewing angles
343
  size = 320 # Size of each rendered image
 
538
  )
539
 
540
  # Set up event handlers
541
+ @spaces.GPU(duration=20) # Add GPU decorator to the generate function
542
  def generate(prompt, guidance_scale, num_steps):
543
  try:
544
  torch.cuda.empty_cache() # Clear GPU memory before starting
 
551
  print(error_msg)
552
  return None, error_msg
553
 
554
+ @spaces.GPU(duration=20)
555
  def refine(input_image, prompt, steps, guidance_scale):
556
  try:
557
  torch.cuda.empty_cache() # Clear GPU memory before starting