A19grey commited on
Commit
4bfe855
1 Parent(s): d893f72

added last updated notice to page and try to fix dimension mismatch warning

Browse files
Files changed (2) hide show
  1. app.py +29 -14
  2. requirements.txt +2 -1
app.py CHANGED
@@ -11,6 +11,9 @@ import os
11
  import trimesh
12
  import time
13
  import timm # Add this import
 
 
 
14
 
15
  # Ensure timm is properly loaded
16
  print(f"Timm version: {timm.__version__}")
@@ -137,13 +140,15 @@ def predict_depth(input_image):
137
  depth = depth.squeeze()
138
 
139
  # Print debug information
140
- print(f"Depth shape: {depth.shape}")
141
- print(f"Image shape: {image.shape}")
 
 
 
 
142
 
143
- # Ensure depth and image have the same dimensions
144
- if depth.shape != image.shape[2:]:
145
- # Resize depth to match image dimensions
146
- depth = np.resize(depth, image.shape[2:])
147
 
148
  # No downsampling
149
  downscale_factor = 1
@@ -185,28 +190,38 @@ def predict_depth(input_image):
185
  os.remove(temp_file)
186
 
187
  # Create the Gradio interface with appropriate input and output components.
 
 
188
  iface = gr.Interface(
189
  fn=predict_depth,
190
  inputs=gr.Image(type="filepath"),
191
  outputs=[
192
- gr.Image(type="filepath", label="Depth Map"), # Displays the depth map image
193
- gr.Textbox(label="Focal Length or Error Message"), # Shows focal length or error messages
194
- gr.File(label="Download Raw Depth Map (CSV)"), # Allows downloading the raw depth data
195
- gr.Model3D(label="View 3D Model"), # For viewing the 3D model
196
- gr.File(label="Download 3D Model (OBJ)") # For downloading the 3D model
197
  ],
198
  title="DepthPro Demo with 3D Visualization",
199
  description=(
200
  "An enhanced demo that creates a textured 3D model from the input image and depth map.\n\n"
201
- "Forked from https://huggingface.co/spaces/akhaliq/depth-pro and model from https://huggingface.co/apple/DepthPro"
202
  "**Instructions:**\n"
203
  "1. Upload an image.\n"
204
  "2. The app will predict the depth map, display it, and provide the focal length.\n"
205
  "3. Download the raw depth data as a CSV file.\n"
206
  "4. View the generated 3D model textured with the original image.\n"
207
- "5. Download the 3D model as an OBJ file if desired."
 
208
  ),
209
  )
210
 
211
  # Launch the Gradio interface with sharing enabled
212
- iface.launch(share=True) # share=True allows you to share the interface with others.
 
 
 
 
 
 
 
 
11
  import trimesh
12
  import time
13
  import timm # Add this import
14
+ import subprocess
15
+ import cv2 # Add this import
16
+ from datetime import datetime
17
 
18
  # Ensure timm is properly loaded
19
  print(f"Timm version: {timm.__version__}")
 
140
  depth = depth.squeeze()
141
 
142
  # Print debug information
143
+ print(f"Original depth shape: {depth.shape}")
144
+ print(f"Original image shape: {image.shape}")
145
+
146
+ # Resize depth to match image dimensions
147
+ image_height, image_width = image.shape[2], image.shape[3]
148
+ depth = cv2.resize(depth, (image_width, image_height), interpolation=cv2.INTER_LINEAR)
149
 
150
+ print(f"Resized depth shape: {depth.shape}")
151
+ print(f"Final image shape: {image.shape}")
 
 
152
 
153
  # No downsampling
154
  downscale_factor = 1
 
190
  os.remove(temp_file)
191
 
192
  # Create the Gradio interface with appropriate input and output components.
193
+ last_updated = get_last_commit_timestamp()
194
+
195
  iface = gr.Interface(
196
  fn=predict_depth,
197
  inputs=gr.Image(type="filepath"),
198
  outputs=[
199
+ gr.Image(type="filepath", label="Depth Map"),
200
+ gr.Textbox(label="Focal Length or Error Message"),
201
+ gr.File(label="Download Raw Depth Map (CSV)"),
202
+ gr.Model3D(label="View 3D Model"),
203
+ gr.File(label="Download 3D Model (OBJ)")
204
  ],
205
  title="DepthPro Demo with 3D Visualization",
206
  description=(
207
  "An enhanced demo that creates a textured 3D model from the input image and depth map.\n\n"
208
+ "Forked from https://huggingface.co/spaces/akhaliq/depth-pro and model from https://huggingface.co/apple/DepthPro\n"
209
  "**Instructions:**\n"
210
  "1. Upload an image.\n"
211
  "2. The app will predict the depth map, display it, and provide the focal length.\n"
212
  "3. Download the raw depth data as a CSV file.\n"
213
  "4. View the generated 3D model textured with the original image.\n"
214
+ "5. Download the 3D model as an OBJ file if desired.\n\n"
215
+ f"Last updated: {last_updated}"
216
  ),
217
  )
218
 
219
  # Launch the Gradio interface with sharing enabled
220
+ iface.launch(share=True) # share=True allows you to share the interface with others.
221
+
222
+ def get_last_commit_timestamp():
223
+ try:
224
+ timestamp = subprocess.check_output(['git', 'log', '-1', '--format=%cd', '--date=iso']).decode('utf-8').strip()
225
+ return datetime.fromisoformat(timestamp).strftime("%Y-%m-%d %H:%M:%S")
226
+ except Exception:
227
+ return "Unknown"
requirements.txt CHANGED
@@ -6,4 +6,5 @@ torchvision
6
  pillow_heif==0.8.0
7
  timm
8
  trimesh==3.22.1
9
- gradio
 
 
6
  pillow_heif==0.8.0
7
  timm
8
  trimesh==3.22.1
9
+ gradio
10
+ opencv-python==4.5.5.64