akashch1512 commited on
Commit
4cc7b02
路
1 Parent(s): b45e3cf

Update 3D viewer scripts and fix output order in prediction function

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -69,9 +69,12 @@ def _viewer(rgb: np.ndarray, height16: Image.Image, meta: dict) -> str:
69
  <iframe title="3D height visualization" style="width:100%;height:620px;border:0;border-radius:10px;"
70
  srcdoc='<!doctype html><meta charset="utf-8"><style>html,body{{margin:0;height:100%;overflow:hidden;background:#101417}}canvas{{display:block}}#info{{position:fixed;top:12px;left:12px;padding:9px 11px;color:#edf2f2;background:#182126dd;border:1px solid #33434a;border-radius:7px;font:13px system-ui,sans-serif}}</style>
71
  <div id="info">Drag to orbit 路 scroll to zoom</div>
72
- <script src="https://cdn.jsdelivr.net/npm/three@0.161.0/build/three.min.js">{close_script}
73
- <script src="https://cdn.jsdelivr.net/npm/three@0.161.0/examples/js/controls/OrbitControls.js">{close_script}
74
  <script>
 
 
 
75
  const data=JSON.parse('{payload}'), meta=data.meta;
76
  const scene=new THREE.Scene(); scene.background=new THREE.Color(0x101417);
77
  scene.add(new THREE.HemisphereLight(0xd9efff,0x26302d,1.3));
@@ -121,7 +124,7 @@ def predict(image_path: str | None, gsd: float):
121
  "gsd_m": scene_meta.gsd_m, "size_px": [rgb.shape[1], rgb.shape[0]]}
122
  info = (f"Height range: {float(np.nanmin(height)):.2f} to "
123
  f"{float(np.nanmax(height)):.2f} m | GSD: {scene_meta.gsd_m:.3f} m/px")
124
- return Image.fromarray(rgb), Image.fromarray(encoded, mode="RGB"), _viewer(rgb, Image.fromarray(encoded, mode="RGB"), metadata), info
125
  except Exception as exc:
126
  raise gr.Error(f"Inference failed: {exc}") from exc
127
 
@@ -135,11 +138,9 @@ with gr.Blocks(title="Single View Height Estimator") as demo:
135
  run = gr.Button("Estimate height", variant="primary")
136
  status = gr.Markdown()
137
  with gr.Column(scale=2):
138
- with gr.Row():
139
- rgb_output = gr.Image(label="RGB", type="pil")
140
- height_output = gr.Image(label="Height16", type="pil")
141
  viewer = gr.HTML(label="3D visualization")
142
- run.click(predict, inputs=[image, gsd], outputs=[rgb_output, height_output, viewer, status])
143
 
144
 
145
  if __name__ == "__main__":
 
69
  <iframe title="3D height visualization" style="width:100%;height:620px;border:0;border-radius:10px;"
70
  srcdoc='<!doctype html><meta charset="utf-8"><style>html,body{{margin:0;height:100%;overflow:hidden;background:#101417}}canvas{{display:block}}#info{{position:fixed;top:12px;left:12px;padding:9px 11px;color:#edf2f2;background:#182126dd;border:1px solid #33434a;border-radius:7px;font:13px system-ui,sans-serif}}</style>
71
  <div id="info">Drag to orbit 路 scroll to zoom</div>
72
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/build/three.min.js">{close_script}
73
+ <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js">{close_script}
74
  <script>
75
+ window.addEventListener('error', (event) => {{
76
+ document.getElementById('info').textContent = '3D viewer error: ' + event.message;
77
+ }});
78
  const data=JSON.parse('{payload}'), meta=data.meta;
79
  const scene=new THREE.Scene(); scene.background=new THREE.Color(0x101417);
80
  scene.add(new THREE.HemisphereLight(0xd9efff,0x26302d,1.3));
 
124
  "gsd_m": scene_meta.gsd_m, "size_px": [rgb.shape[1], rgb.shape[0]]}
125
  info = (f"Height range: {float(np.nanmin(height)):.2f} to "
126
  f"{float(np.nanmax(height)):.2f} m | GSD: {scene_meta.gsd_m:.3f} m/px")
127
+ return Image.fromarray(encoded, mode="RGB"), _viewer(rgb, Image.fromarray(encoded, mode="RGB"), metadata), info
128
  except Exception as exc:
129
  raise gr.Error(f"Inference failed: {exc}") from exc
130
 
 
138
  run = gr.Button("Estimate height", variant="primary")
139
  status = gr.Markdown()
140
  with gr.Column(scale=2):
141
+ height_output = gr.Image(label="Height16", type="pil")
 
 
142
  viewer = gr.HTML(label="3D visualization")
143
+ run.click(predict, inputs=[image, gsd], outputs=[height_output, viewer, status])
144
 
145
 
146
  if __name__ == "__main__":