init
Browse files
app.py
CHANGED
|
@@ -114,23 +114,36 @@ def camera_understanding(image_src, question, seed, progress=gr.Progress(track_t
|
|
| 114 |
cam = gen.get_cam(text)
|
| 115 |
|
| 116 |
bgr = np.array(image)[:, :, ::-1].astype(np.float32) / 255.0
|
| 117 |
-
rgb = bgr[:, :, ::-1].copy()
|
| 118 |
image_tensor = torch.from_numpy(rgb).permute(2, 0, 1).unsqueeze(0)
|
| 119 |
-
single_batch = {
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
| 123 |
|
| 124 |
figs = make_perspective_figures(single_batch, single_batch, n_pairs=1)
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
| 126 |
for k, fig in figs.items():
|
| 127 |
if "up_field" in k:
|
| 128 |
-
|
| 129 |
elif "latitude_field" in k:
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
plt.close(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
return text
|
| 134 |
|
| 135 |
|
| 136 |
@torch.inference_mode()
|
|
@@ -227,8 +240,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 227 |
understanding_button = gr.Button("Chat")
|
| 228 |
understanding_output = gr.Textbox(label="Response")
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
|
| 233 |
with gr.Accordion("Advanced options", open=False):
|
| 234 |
und_seed_input = gr.Number(label="Seed", precision=0, value=42)
|
|
@@ -255,7 +268,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 255 |
understanding_button.click(
|
| 256 |
camera_understanding,
|
| 257 |
inputs=[image_input, und_seed_input],
|
| 258 |
-
outputs=[understanding_output
|
| 259 |
)
|
| 260 |
|
| 261 |
demo.launch(share=True)
|
|
|
|
| 114 |
cam = gen.get_cam(text)
|
| 115 |
|
| 116 |
bgr = np.array(image)[:, :, ::-1].astype(np.float32) / 255.0
|
| 117 |
+
rgb = bgr[:, :, ::-1].copy()
|
| 118 |
image_tensor = torch.from_numpy(rgb).permute(2, 0, 1).unsqueeze(0)
|
| 119 |
+
single_batch = {
|
| 120 |
+
"image": image_tensor,
|
| 121 |
+
"up_field": cam[:2].unsqueeze(0),
|
| 122 |
+
"latitude_field": cam[2:].unsqueeze(0),
|
| 123 |
+
}
|
| 124 |
|
| 125 |
figs = make_perspective_figures(single_batch, single_batch, n_pairs=1)
|
| 126 |
+
saved_paths = []
|
| 127 |
+
save_dir = "temp/"
|
| 128 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 129 |
+
|
| 130 |
for k, fig in figs.items():
|
| 131 |
if "up_field" in k:
|
| 132 |
+
suffix = "_up"
|
| 133 |
elif "latitude_field" in k:
|
| 134 |
+
suffix = "_lat"
|
| 135 |
+
else:
|
| 136 |
+
suffix = f"_{k}"
|
| 137 |
+
out_path = os.path.join(save_dir, f"camera_map_vis{suffix}.png")
|
| 138 |
+
plt.tight_layout()
|
| 139 |
+
fig.savefig(out_path, dpi=200, bbox_inches='tight', pad_inches=0)
|
| 140 |
plt.close(fig)
|
| 141 |
+
saved_paths.append(out_path)
|
| 142 |
+
|
| 143 |
+
img_up = Image.open(saved_paths[0]).convert("RGB")
|
| 144 |
+
img_lat = Image.open(saved_paths[1]).convert("RGB")
|
| 145 |
|
| 146 |
+
return text, img_up, img_lat
|
| 147 |
|
| 148 |
|
| 149 |
@torch.inference_mode()
|
|
|
|
| 240 |
understanding_button = gr.Button("Chat")
|
| 241 |
understanding_output = gr.Textbox(label="Response")
|
| 242 |
|
| 243 |
+
camera1 = gr.Gallery(label="Camera Maps", columns=1, rows=1)
|
| 244 |
+
camera2 = gr.Gallery(label="Camera Maps", columns=1, rows=1)
|
| 245 |
|
| 246 |
with gr.Accordion("Advanced options", open=False):
|
| 247 |
und_seed_input = gr.Number(label="Seed", precision=0, value=42)
|
|
|
|
| 268 |
understanding_button.click(
|
| 269 |
camera_understanding,
|
| 270 |
inputs=[image_input, und_seed_input],
|
| 271 |
+
outputs=[understanding_output, camera1, camera2]
|
| 272 |
)
|
| 273 |
|
| 274 |
demo.launch(share=True)
|