Spaces:
Runtime error
Runtime error
Commit
·
8866f56
1
Parent(s):
ab5ee38
Implement visualization directory management in app.py and navigation.py. Added clear_visualization_directory function to prevent users from seeing each other's generated images. Updated IMAGE_PATHS with new sample images and removed unused imports.
Browse files- app.py +36 -6
- navigation.py +7 -1
app.py
CHANGED
@@ -7,7 +7,7 @@ subprocess.check_call([
|
|
7 |
])
|
8 |
|
9 |
from typing import List, Literal
|
10 |
-
from pathlib import Path
|
11 |
from functools import partial
|
12 |
import spaces
|
13 |
import gradio as gr
|
@@ -16,12 +16,14 @@ import torch
|
|
16 |
from omegaconf import OmegaConf
|
17 |
from modeling.pipeline import VMemPipeline
|
18 |
from diffusers.utils import export_to_video
|
19 |
-
from scipy.spatial.transform import Rotation, Slerp
|
20 |
from navigation import Navigator
|
21 |
-
from PIL import Image
|
22 |
-
from utils import tensor_to_pil,
|
23 |
import os
|
24 |
-
import glob
|
|
|
|
|
25 |
|
26 |
|
27 |
|
@@ -46,6 +48,28 @@ IMAGE_PATHS = ['test_samples/oxford.jpg',
|
|
46 |
'test_samples/jesus.jpg',]
|
47 |
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# If no images found, create placeholders
|
50 |
if not IMAGE_PATHS:
|
51 |
def create_placeholder_images(num_samples=5, height=HEIGHT, width=WIDTH):
|
@@ -355,6 +379,9 @@ def render_demonstrate(
|
|
355 |
gr.Warning("Please upload an image first")
|
356 |
return "Selection", None, None, None
|
357 |
try:
|
|
|
|
|
|
|
358 |
# Load image and prepare for navigation
|
359 |
result = load_image_for_navigation(image_path)
|
360 |
|
@@ -416,6 +443,9 @@ def render_demonstrate(
|
|
416 |
|
417 |
def start_navigation(evt: gr.SelectData):
|
418 |
try:
|
|
|
|
|
|
|
419 |
# Get the selected image path
|
420 |
selected_path = IMAGE_PATHS[evt.index]
|
421 |
|
@@ -824,7 +854,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue="blue")) as demo:
|
|
824 |
)
|
825 |
gr.Button(
|
826 |
value="Paper",
|
827 |
-
link="
|
828 |
icon="https://simpleicons.org/icons/arxiv.svg",
|
829 |
elem_classes=["header-button"],
|
830 |
size="md",
|
|
|
7 |
])
|
8 |
|
9 |
from typing import List, Literal
|
10 |
+
# from pathlib import Path
|
11 |
from functools import partial
|
12 |
import spaces
|
13 |
import gradio as gr
|
|
|
16 |
from omegaconf import OmegaConf
|
17 |
from modeling.pipeline import VMemPipeline
|
18 |
from diffusers.utils import export_to_video
|
19 |
+
# from scipy.spatial.transform import Rotation, Slerp
|
20 |
from navigation import Navigator
|
21 |
+
# from PIL import Image
|
22 |
+
from utils import tensor_to_pil, get_default_intrinsics, load_img_and_K, transform_img_and_K
|
23 |
import os
|
24 |
+
# import glob
|
25 |
+
import shutil
|
26 |
+
|
27 |
|
28 |
|
29 |
|
|
|
48 |
'test_samples/jesus.jpg',]
|
49 |
|
50 |
|
51 |
+
def clear_visualization_directory():
|
52 |
+
"""
|
53 |
+
Clear all contents from the visualization directory to prevent users from seeing
|
54 |
+
each other's generated images.
|
55 |
+
"""
|
56 |
+
viz_dir = "./visualization"
|
57 |
+
try:
|
58 |
+
if os.path.exists(viz_dir):
|
59 |
+
shutil.rmtree(viz_dir)
|
60 |
+
os.makedirs(viz_dir, exist_ok=True)
|
61 |
+
print(f"Cleared visualization directory: {viz_dir}")
|
62 |
+
except Exception as e:
|
63 |
+
print(f"Warning: Could not clear visualization directory: {e}")
|
64 |
+
|
65 |
+
|
66 |
+
IMAGE_PATHS = ['test_samples/oxford.jpg',
|
67 |
+
'test_samples/open_door.jpg',
|
68 |
+
'test_samples/living_room.jpg',
|
69 |
+
'test_samples/arc_de_tromphe.jpeg',
|
70 |
+
'test_samples/changi.jpg',
|
71 |
+
'test_samples/jesus.jpg',]
|
72 |
+
|
73 |
# If no images found, create placeholders
|
74 |
if not IMAGE_PATHS:
|
75 |
def create_placeholder_images(num_samples=5, height=HEIGHT, width=WIDTH):
|
|
|
379 |
gr.Warning("Please upload an image first")
|
380 |
return "Selection", None, None, None
|
381 |
try:
|
382 |
+
# Clear visualization directory to prevent users from seeing each other's generated images
|
383 |
+
clear_visualization_directory()
|
384 |
+
|
385 |
# Load image and prepare for navigation
|
386 |
result = load_image_for_navigation(image_path)
|
387 |
|
|
|
443 |
|
444 |
def start_navigation(evt: gr.SelectData):
|
445 |
try:
|
446 |
+
# Clear visualization directory to prevent users from seeing each other's generated images
|
447 |
+
clear_visualization_directory()
|
448 |
+
|
449 |
# Get the selected image path
|
450 |
selected_path = IMAGE_PATHS[evt.index]
|
451 |
|
|
|
854 |
)
|
855 |
gr.Button(
|
856 |
value="Paper",
|
857 |
+
link="http://arxiv.org/abs/2506.18903",
|
858 |
icon="https://simpleicons.org/icons/arxiv.svg",
|
859 |
elem_classes=["header-button"],
|
860 |
size="md",
|
navigation.py
CHANGED
@@ -7,7 +7,7 @@ import json
|
|
7 |
from typing import List, Optional, Tuple
|
8 |
import scipy.spatial.transform as spt
|
9 |
from omegaconf import OmegaConf
|
10 |
-
|
11 |
|
12 |
from modeling.pipeline import VMemPipeline
|
13 |
from utils import load_img_and_K, transform_img_and_K, get_default_intrinsics
|
@@ -65,6 +65,11 @@ class Navigator:
|
|
65 |
"transform_matrix": initial_pose.tolist() if isinstance(initial_pose, np.ndarray) else initial_pose
|
66 |
})
|
67 |
|
|
|
|
|
|
|
|
|
|
|
68 |
return initial_frame
|
69 |
|
70 |
def initialize_pipeline(self, image_tensor, initial_pose, initial_K):
|
@@ -428,3 +433,4 @@ class Navigator:
|
|
428 |
|
429 |
|
430 |
|
|
|
|
7 |
from typing import List, Optional, Tuple
|
8 |
import scipy.spatial.transform as spt
|
9 |
from omegaconf import OmegaConf
|
10 |
+
import shutil
|
11 |
|
12 |
from modeling.pipeline import VMemPipeline
|
13 |
from utils import load_img_and_K, transform_img_and_K, get_default_intrinsics
|
|
|
65 |
"transform_matrix": initial_pose.tolist() if isinstance(initial_pose, np.ndarray) else initial_pose
|
66 |
})
|
67 |
|
68 |
+
# clean the visualization folder
|
69 |
+
if os.path.exists("visualization"):
|
70 |
+
shutil.rmtree("visualization")
|
71 |
+
os.makedirs("visualization", exist_ok=True)
|
72 |
+
|
73 |
return initial_frame
|
74 |
|
75 |
def initialize_pipeline(self, image_tensor, initial_pose, initial_K):
|
|
|
433 |
|
434 |
|
435 |
|
436 |
+
|