alexnasa commited on
Commit
8c4572d
·
verified ·
1 Parent(s): 1d930bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -105,7 +105,8 @@ def preprocess_image(image_array, session_id):
105
  if image_array is None:
106
  return "❌ Please upload an image first.", None, gr.update(interactive=True), gr.update(interactive=True)
107
 
108
- os.makedirs(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id, exist_ok=True)
 
109
 
110
  img = Image.fromarray(image_array)
111
  saved_image_path = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id, f"{session_id}.png")
@@ -117,7 +118,7 @@ def preprocess_image(image_array, session_id):
117
  ], check=True, capture_output=True, text=True)
118
  except subprocess.CalledProcessError as e:
119
  err = f"❌ Preprocess failed (exit {e.returncode}).\n\n{e.stdout}\n{e.stderr}"
120
- shutil.rmtree(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id)
121
  return err, None, {}, gr.update(interactive=True), gr.update(interactive=True)
122
 
123
  crop_dir = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id, "cropped")
 
105
  if image_array is None:
106
  return "❌ Please upload an image first.", None, gr.update(interactive=True), gr.update(interactive=True)
107
 
108
+ base_dir = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id)
109
+ os.makedirs(base_dir, exist_ok=True)
110
 
111
  img = Image.fromarray(image_array)
112
  saved_image_path = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id, f"{session_id}.png")
 
118
  ], check=True, capture_output=True, text=True)
119
  except subprocess.CalledProcessError as e:
120
  err = f"❌ Preprocess failed (exit {e.returncode}).\n\n{e.stdout}\n{e.stderr}"
121
+ shutil.rmtree(base_dir, ignore_errors=True)
122
  return err, None, {}, gr.update(interactive=True), gr.update(interactive=True)
123
 
124
  crop_dir = os.path.join(os.environ["PIXEL3DMM_PREPROCESSED_DATA"], session_id, "cropped")