Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -418,36 +418,40 @@ def apply_prompt(meta_data, new_prompt):
|
|
418 |
|
419 |
@spaces.GPU(duration=30)
|
420 |
def on_image_change(filepath):
|
421 |
-
# Extract the filename without extension
|
422 |
filename = os.path.splitext(os.path.basename(filepath))[0]
|
423 |
|
424 |
-
if filename in ["example1",
|
|
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
global num_inference_steps
|
432 |
-
num_inference_steps = 10
|
433 |
-
scale_value = 7
|
434 |
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
|
439 |
-
|
440 |
-
|
441 |
-
new_prompt = "a realistic photo of a female warrior, flowing dark purple or black hair, bronze shoulder armour, leather chest piece, sky background with clouds"
|
442 |
|
443 |
-
|
444 |
-
|
445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
|
447 |
-
|
448 |
-
|
449 |
|
450 |
-
return
|
|
|
451 |
|
452 |
|
453 |
def update_value(value, layer_type, resolution, depth):
|
|
|
418 |
|
419 |
@spaces.GPU(duration=30)
|
420 |
def on_image_change(filepath):
|
|
|
421 |
filename = os.path.splitext(os.path.basename(filepath))[0]
|
422 |
|
423 |
+
if filename not in ["example1","example3","example4"]:
|
424 |
+
return filepath, None, None, None, None, None
|
425 |
|
426 |
+
# 1) load the raw state (might contain CUDA tensors!)
|
427 |
+
caption, real_latents, inversed_latents, saved_weights = load_state_from_file(
|
428 |
+
f"assets/{filename}-turbo.pkl"
|
429 |
+
)
|
|
|
|
|
|
|
|
|
430 |
|
431 |
+
# 2) immediately move all tensors to CPU
|
432 |
+
real_cpu = real_latents.detach().cpu()
|
433 |
+
inversed_cpu= [x.detach().cpu() for x in inversed_latents]
|
434 |
|
435 |
+
# 3) repack a truly CPU-only state
|
436 |
+
cpu_meta_data = (caption, real_cpu, inversed_cpu, saved_weights)
|
|
|
437 |
|
438 |
+
# 4) your existing logic can then run on GPU, but it will
|
439 |
+
# consume only CPU tensors and return only CPU tensors
|
440 |
+
_, _, _, global_weights = cpu_meta_data
|
441 |
+
global weights; weights = global_weights
|
442 |
+
num_inference_steps = 10
|
443 |
+
if filename == "example1":
|
444 |
+
scale_value, new_prompt = 8, "a photo of a tree, summer, colourful"
|
445 |
+
elif filename == "example3":
|
446 |
+
scale_value, new_prompt = 6, "a realistic photo of a female warrior, ..."
|
447 |
+
else:
|
448 |
+
scale_value, new_prompt = 13, "a photo of plastic bottle on some sand, ..."
|
449 |
|
450 |
+
update_scale(scale_value)
|
451 |
+
img = apply_prompt(cpu_meta_data, new_prompt)
|
452 |
|
453 |
+
# 5) return only CPU objects (img is still a numpy array)
|
454 |
+
return filepath, img, cpu_meta_data, num_inference_steps, scale_value, scale_value
|
455 |
|
456 |
|
457 |
def update_value(value, layer_type, resolution, depth):
|