alexnasa commited on
Commit
58c9f2e
·
1 Parent(s): d0853f7
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -235,6 +235,15 @@ def run_pipeline(image_array, state):
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:
@@ -263,6 +272,7 @@ with demo:
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)
 
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
+ # Cleanup on unload
239
+ def cleanup(state):
240
+ sid = state.get("session_id")
241
+ if sid:
242
+ d1 = os.path.join(env["PIXEL3DMM_PREPROCESSED_DATA"], sid)
243
+ d2 = os.path.join(env["PIXEL3DMM_TRACKING_OUTPUT"], sid)
244
+ shutil.rmtree(d1, ignore_errors=True)
245
+ shutil.rmtree(d2, ignore_errors=True)
246
+
247
  # Build Gradio UI
248
  demo = gr.Blocks()
249
  with demo:
 
272
 
273
  image_in.upload(fn=reset_all, inputs=None, outputs=[crop_img, normals_img, uv_img, track_img, mesh_file, status, state, run_btn])
274
 
275
+ demo.unload(fn=cleanup, inputs=[state], outputs=[])
276
 
277
  demo.queue()
278
  demo.launch(share=True, ssr_mode=False)