Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 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)
|
| 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
|