A19grey commited on
Commit
ced7c47
·
1 Parent(s): 4322221

fix error not finding temp file

Browse files
Files changed (2) hide show
  1. app.py +10 -3
  2. history.md +18 -0
app.py CHANGED
@@ -260,6 +260,13 @@ def predict_depth(input_image):
260
  def create_3d_model(depth_csv, image_path, focallength_px, simplification_factor, smoothing_iterations, thin_threshold):
261
  try:
262
  depth = np.loadtxt(depth_csv, delimiter=',')
 
 
 
 
 
 
 
263
  view_model_path, download_model_path = generate_3d_model(
264
  depth, image_path, focallength_px,
265
  simplification_factor, smoothing_iterations, thin_threshold
@@ -317,13 +324,13 @@ with gr.Blocks() as iface:
317
  model_status = gr.Textbox(label="3D Model Status")
318
 
319
  # Hidden components to store intermediate results
320
- hidden_image_path = gr.State()
321
  hidden_focal_length = gr.State()
322
 
323
  input_image.change(
324
- predict_depth,
325
  inputs=[input_image],
326
- outputs=[depth_map, focal_length, raw_depth_csv, hidden_image_path, hidden_focal_length]
327
  )
328
 
329
  generate_3d_button.click(
 
260
  def create_3d_model(depth_csv, image_path, focallength_px, simplification_factor, smoothing_iterations, thin_threshold):
261
  try:
262
  depth = np.loadtxt(depth_csv, delimiter=',')
263
+
264
+ # Check if the image file exists
265
+ if not os.path.exists(image_path):
266
+ raise FileNotFoundError(f"Image file not found: {image_path}")
267
+
268
+ print(f"Loading image from: {image_path}")
269
+
270
  view_model_path, download_model_path = generate_3d_model(
271
  depth, image_path, focallength_px,
272
  simplification_factor, smoothing_iterations, thin_threshold
 
324
  model_status = gr.Textbox(label="3D Model Status")
325
 
326
  # Hidden components to store intermediate results
327
+ hidden_image_path = gr.State("temp_input_image.png")
328
  hidden_focal_length = gr.State()
329
 
330
  input_image.change(
331
+ lambda x: (x, x), # This lambda function returns the image path twice
332
  inputs=[input_image],
333
+ outputs=[hidden_image_path, input_image] # Update hidden_image_path and keep the visible input_image
334
  )
335
 
336
  generate_3d_button.click(
history.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Change Log
2
+
3
+ ## 2024-10-05 21:20 PST
4
+ ### 3D Model Generation File Access Error
5
+ - Problem: When attempting to generate the 3D model, an error occurred: "[Errno 2] No such file or directory: '/tmp/tmppgls861k.png'"
6
+ - This suggests that the temporary file created during the depth map generation is not accessible or has been deleted before the 3D model generation process.
7
+ - Next steps: Investigate the file handling in the `create_3d_model` function and ensure temporary files are properly managed and accessible.
8
+
9
+ ## 2024-10-05 21:13 PST
10
+ ### CUDA Initialization Error Fix
11
+ - Problem: CUDA was being initialized in the main process, causing an error in the Spaces Stateless GPU environment.
12
+ - Changes made:
13
+ 1. Modified `np.savetxt` to ensure depth is converted to a CPU numpy array if it's a torch.Tensor.
14
+ 2. Explicitly converted `focallength_px` to a float.
15
+ 3. Added more print statements throughout the `predict_depth` function for improved logging and debugging.
16
+ 4. Added a print statement just before returning from the `predict_depth` function to log all return values.
17
+ - These changes aim to prevent CUDA initialization in the main process and provide more detailed logging for troubleshooting.
18
+