Yosun commited on
Commit
5ed3ea2
·
1 Parent(s): b77f070

Wrap generate in try-except to surface backend errors

Browse files
Files changed (1) hide show
  1. app.py +28 -18
app.py CHANGED
@@ -136,31 +136,41 @@ def generate(files: Any):
136
  )
137
  return None, None, err_placeholder, status
138
 
139
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
140
- model.to(device)
 
 
141
 
142
- gaussians = model(result.images)[0]
143
 
144
- video_path = tempfile.mktemp(suffix=".mp4")
145
- ply_path = tempfile.mktemp(suffix=".ply")
146
 
147
- viz.turntable(gaussians, video_path, sweep_deg=None)
148
- gaussians.save_ply(ply_path)
149
 
150
- center, radius = viz.scene_center_radius(gaussians)
151
- cx, cy, cz = center.tolist()
152
 
153
- viewer_html = build_viewer_iframe(ply_path, cx=cx, cy=cy, cz=cz, r=radius)
154
 
155
- status = (
156
- f"Loaded {result.image_count} still image(s) and selected "
157
- f"{result.selected_video_frames} of {result.decoded_video_frames} decoded video frame(s).\n"
158
- f"Total ZipSplat views: {len(result.images)}."
159
- )
160
- if result.warnings:
161
- status += "\n\nWarnings:\n" + "\n".join(result.warnings)
162
 
163
- return video_path, ply_path, viewer_html, status
 
 
 
 
 
 
 
 
164
 
165
 
166
  # ----------------------------------------------------------------------------
 
136
  )
137
  return None, None, err_placeholder, status
138
 
139
+ import traceback
140
+ try:
141
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
142
+ model.to(device)
143
 
144
+ gaussians = model(result.images)[0]
145
 
146
+ video_path = tempfile.mktemp(suffix=".mp4")
147
+ ply_path = tempfile.mktemp(suffix=".ply")
148
 
149
+ viz.turntable(gaussians, video_path, sweep_deg=None)
150
+ gaussians.save_ply(ply_path)
151
 
152
+ center, radius = viz.scene_center_radius(gaussians)
153
+ cx, cy, cz = center.tolist()
154
 
155
+ viewer_html = build_viewer_iframe(ply_path, cx=cx, cy=cy, cz=cz, r=radius)
156
 
157
+ status = (
158
+ f"Loaded {result.image_count} still image(s) and selected "
159
+ f"{result.selected_video_frames} of {result.decoded_video_frames} decoded video frame(s).\n"
160
+ f"Total ZipSplat views: {len(result.images)}."
161
+ )
162
+ if result.warnings:
163
+ status += "\n\nWarnings:\n" + "\n".join(result.warnings)
164
 
165
+ return video_path, ply_path, viewer_html, status
166
+ except Exception as e:
167
+ err_msg = f"Backend Crash during generation:\n{traceback.format_exc()}"
168
+ err_html = (
169
+ f'<div style="height: 500px; padding: 20px; overflow-y: auto; '
170
+ f'background: #080b12; color: #f87171; border-radius: 12px; font-family: monospace;">'
171
+ f"{err_msg.replace(chr(10), '<br>')}</div>"
172
+ )
173
+ return None, None, err_html, err_msg
174
 
175
 
176
  # ----------------------------------------------------------------------------