Spaces:
Running
on
Zero
Running
on
Zero
update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# %%
|
2 |
from typing import Optional, Tuple
|
3 |
from einops import rearrange
|
4 |
import torch
|
@@ -385,9 +384,8 @@ def main_fn(
|
|
385 |
rgb = dont_use_too_much_green(rgb)
|
386 |
return to_pil_images(rgb)
|
387 |
|
388 |
-
|
389 |
-
|
390 |
-
default_outputs = ['/workspace/output/gradio/ncut_0.jpg', '/workspace/output/gradio/ncut_1.jpg', '/workspace/output/gradio/ncut_2.jpg', '/workspace/output/gradio/ncut_3.jpg', '/workspace/output/gradio/ncut_4.jpg', '/workspace/output/gradio/ncut_5.jpg']
|
391 |
|
392 |
demo = gr.Interface(
|
393 |
main_fn,
|
@@ -410,61 +408,4 @@ demo = gr.Interface(
|
|
410 |
]
|
411 |
)
|
412 |
|
413 |
-
demo.launch(
|
414 |
-
|
415 |
-
# %%
|
416 |
-
|
417 |
-
|
418 |
-
# # %%
|
419 |
-
# from ncut_pytorch import NCUT, rgb_from_tsne_3d
|
420 |
-
|
421 |
-
# i_layer = -1
|
422 |
-
# inp = block_outputs[i_layer]
|
423 |
-
# eigvecs, eigvals = NCUT(
|
424 |
-
# num_eig=1000, num_sample=10000, device="cuda:0", affinity_focal_gamma=0.3, knn=10
|
425 |
-
# ).fit_transform(inp.reshape(-1, inp.shape[-1]))
|
426 |
-
# print(eigvecs.shape, eigvals.shape)
|
427 |
-
# # %%
|
428 |
-
# X_3d, rgb = rgb_from_tsne_3d(
|
429 |
-
# eigvecs[:, :100], num_sample=1000, perplexity=500, knn=10, seed=42
|
430 |
-
# )
|
431 |
-
# # %%
|
432 |
-
# image_rgb = rgb.reshape(*inp.shape[:-1], 3)
|
433 |
-
# # make sure the foval 20% of the image is red leading
|
434 |
-
# x1, x2 = int(image_rgb.shape[1] * 0.4), int(image_rgb.shape[1] * 0.6)
|
435 |
-
# y1, y2 = int(image_rgb.shape[2] * 0.4), int(image_rgb.shape[2] * 0.6)
|
436 |
-
# sum_values = image_rgb[:, x1:x2, y1:y2].mean((0, 1, 2))
|
437 |
-
# sorted_indices = sum_values.argsort(descending=True)
|
438 |
-
# image_rgb = image_rgb[:, :, :, sorted_indices]
|
439 |
-
|
440 |
-
# import matplotlib.pyplot as plt
|
441 |
-
|
442 |
-
# fig, axes = plt.subplots(2, 3, figsize=(15, 10))
|
443 |
-
# for i, ax in enumerate(axes.flat):
|
444 |
-
# ax.imshow(image_rgb[i])
|
445 |
-
# ax.axis("off")
|
446 |
-
|
447 |
-
# %%
|
448 |
-
save_dir = "/workspace/output/gradio"
|
449 |
-
import os
|
450 |
-
|
451 |
-
os.makedirs(save_dir, exist_ok=True)
|
452 |
-
|
453 |
-
images = ['/workspace/guitars/lespual1.png', '/workspace/guitars/lespual2.png', '/workspace/guitars/lespual3.png', '/workspace/guitars/lespual4.png', '/workspace/guitars/lespual5.png', '/workspace/guitars/acoustic1.png']
|
454 |
-
images = [Image.open(image).convert("RGB") for image in images]
|
455 |
-
for i, image in enumerate(images):
|
456 |
-
image = image.resize((512, 512))
|
457 |
-
image.save(os.path.join(save_dir, f"image_{i}.jpg"), "JPEG", quality=70)
|
458 |
-
# %%
|
459 |
-
images = [(image, '') for image in images]
|
460 |
-
image_rbg = main_fn(images)
|
461 |
-
# %%
|
462 |
-
for i, rgb in enumerate(image_rbg):
|
463 |
-
rgb = rgb.resize((512, 512), Image.NEAREST)
|
464 |
-
rgb.save(os.path.join(save_dir, f"ncut_{i}.jpg"), "JPEG", quality=70)
|
465 |
-
# %%
|
466 |
-
for i, rgb in enumerate(image_rgb):
|
467 |
-
rgb = Image.fromarray((rgb * 255).cpu().numpy().astype(np.uint8))
|
468 |
-
rgb.save(os.path.join(save_dir, f"ncut_{i}.png"))
|
469 |
-
# %%
|
470 |
-
%%
|
|
|
|
|
1 |
from typing import Optional, Tuple
|
2 |
from einops import rearrange
|
3 |
import torch
|
|
|
384 |
rgb = dont_use_too_much_green(rgb)
|
385 |
return to_pil_images(rgb)
|
386 |
|
387 |
+
default_images = ['./images/image_0.jpg', './images/image_1.jpg', './images/image_2.jpg', './images/image_3.jpg', './images/image_4.jpg', './images/image_5.jpg']
|
388 |
+
default_outputs = ['./images/ncut_0.jpg', './images/ncut_1.jpg', './images/ncut_2.jpg', './images/ncut_3.jpg', './images/ncut_4.jpg', './images/ncut_5.jpg']
|
|
|
389 |
|
390 |
demo = gr.Interface(
|
391 |
main_fn,
|
|
|
408 |
]
|
409 |
)
|
410 |
|
411 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|