alexnasa commited on
Commit
d0853f7
·
1 Parent(s): 9db6838

download the pie

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -218,28 +218,32 @@ def step4_track(state):
218
  # New: run all steps sequentially
219
  @spaces.GPU()
220
  def run_pipeline(image_array, state):
221
- # Step 1: Preprocess
222
  status1, crop_img, state, _, _ = preprocess_image(image_array, state)
223
  if "❌" in status1:
224
- return status1, None, None, None, None, {}
225
- # Step 2: Normals
226
  status2, normals_img, state, _, _ = step2_normals(state)
227
- # Step 3: UV Map
228
  status3, uv_img, state, _, _ = step3_uv_map(state)
229
- # Step 4: Tracking
230
  status4, track_img, state, _ = step4_track(state)
 
 
 
 
231
  final_status = "\n".join([status1, status2, status3, status4])
232
- return final_status, crop_img, normals_img, uv_img, track_img, state
233
 
234
  # Build Gradio UI
235
  demo = gr.Blocks()
236
  with demo:
237
  gr.Markdown("## Image Processing Pipeline (Single Button)")
238
- gr.Markdown("Upload an image and click 'Run Pipeline' to execute all steps.")
239
  with gr.Row():
240
  with gr.Column():
241
  image_in = gr.Image(label="Upload Image", type="numpy", height=512)
242
- status = gr.Textbox(label="Status", lines=4, interactive=True, value="Upload an image to start.")
243
  state = gr.State({})
244
  with gr.Column():
245
  with gr.Row():
@@ -248,16 +252,17 @@ with demo:
248
  with gr.Row():
249
  uv_img = gr.Image(label="UV Map", height=256)
250
  track_img = gr.Image(label="Tracking", height=256)
 
251
  run_btn = gr.Button("Run Pipeline")
252
 
253
- # Single button click
254
  run_btn.click(
255
  fn=run_pipeline,
256
  inputs=[image_in, state],
257
- outputs=[status, crop_img, normals_img, uv_img, track_img, state]
258
  )
259
 
260
- image_in.upload(fn=reset_all, inputs=None, outputs=[crop_img, normals_img, uv_img, track_img, status, state])
 
261
 
262
  demo.queue()
263
- demo.launch(share=True, ssr_mode=False)
 
218
  # New: run all steps sequentially
219
  @spaces.GPU()
220
  def run_pipeline(image_array, state):
221
+ # Step 1
222
  status1, crop_img, state, _, _ = preprocess_image(image_array, state)
223
  if "❌" in status1:
224
+ return status1, None, None, None, None, None, {}
225
+ # Step 2
226
  status2, normals_img, state, _, _ = step2_normals(state)
227
+ # Step 3
228
  status3, uv_img, state, _, _ = step3_uv_map(state)
229
+ # Step 4
230
  status4, track_img, state, _ = step4_track(state)
231
+ # Locate mesh (.ply)
232
+ mesh_dir = os.path.join(os.environ["PIXEL3DMM_TRACKING_OUTPUT"], state.get("session_id"), "mesh")
233
+ mesh_file = first_file_from_dir(mesh_dir, "ply")
234
+
235
  final_status = "\n".join([status1, status2, status3, status4])
236
+ return final_status, crop_img, normals_img, uv_img, track_img, mesh_file, state
237
 
238
  # Build Gradio UI
239
  demo = gr.Blocks()
240
  with demo:
241
  gr.Markdown("## Image Processing Pipeline (Single Button)")
242
+ gr.Markdown("Upload an image and click 'Run Pipeline' to execute all steps and download the mesh.")
243
  with gr.Row():
244
  with gr.Column():
245
  image_in = gr.Image(label="Upload Image", type="numpy", height=512)
246
+ status = gr.Textbox(label="Status", lines=6, interactive=True, value="Upload an image to start.")
247
  state = gr.State({})
248
  with gr.Column():
249
  with gr.Row():
 
252
  with gr.Row():
253
  uv_img = gr.Image(label="UV Map", height=256)
254
  track_img = gr.Image(label="Tracking", height=256)
255
+ mesh_file = gr.File(label="Download Mesh (.ply)")
256
  run_btn = gr.Button("Run Pipeline")
257
 
 
258
  run_btn.click(
259
  fn=run_pipeline,
260
  inputs=[image_in, state],
261
+ outputs=[status, crop_img, normals_img, uv_img, track_img, mesh_file, state]
262
  )
263
 
264
+ image_in.upload(fn=reset_all, inputs=None, outputs=[crop_img, normals_img, uv_img, track_img, mesh_file, status, state, run_btn])
265
+
266
 
267
  demo.queue()
268
+ demo.launch(share=True, ssr_mode=False)