ghost233lism commited on
Commit
b8338e1
·
verified ·
1 Parent(s): e1dd24c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -199,6 +199,14 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
199
  type="pil",
200
  height=400
201
  )
 
 
 
 
 
 
 
 
202
 
203
  # Function to switch between upload and camera input
204
  def switch_input_source(source):
@@ -217,9 +225,18 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
217
  # Function to handle both input sources
218
  def handle_prediction(input_source, upload_img, camera_img, colormap):
219
  if input_source == "Upload Image":
220
- return predict_depth(upload_img, colormap)
221
  else:
222
- return predict_depth(camera_img, colormap)
 
 
 
 
 
 
 
 
 
223
 
224
  # Examples section
225
  gr.Examples(
@@ -239,7 +256,7 @@ with gr.Blocks(title="Depth Anything AC - Depth Estimation Demo", theme=gr.theme
239
  submit_btn.click(
240
  fn=handle_prediction,
241
  inputs=[input_source, upload_image, camera_image, colormap_choice],
242
- outputs=output_image,
243
  show_progress=True
244
  )
245
 
 
199
  type="pil",
200
  height=400
201
  )
202
+
203
+ # Add download button to match the height of upload controls
204
+ download_btn = gr.DownloadButton(
205
+ label="📥 Download Depth Map",
206
+ variant="secondary",
207
+ size="sm",
208
+ visible=False
209
+ )
210
 
211
  # Function to switch between upload and camera input
212
  def switch_input_source(source):
 
225
  # Function to handle both input sources
226
  def handle_prediction(input_source, upload_img, camera_img, colormap):
227
  if input_source == "Upload Image":
228
+ result = predict_depth(upload_img, colormap)
229
  else:
230
+ result = predict_depth(camera_img, colormap)
231
+
232
+ # Show download button when depth map is generated
233
+ if result is not None:
234
+ # Save result to temporary file for download
235
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
236
+ result.save(temp_file.name)
237
+ return result, gr.update(visible=True, value=temp_file.name)
238
+ else:
239
+ return None, gr.update(visible=False)
240
 
241
  # Examples section
242
  gr.Examples(
 
256
  submit_btn.click(
257
  fn=handle_prediction,
258
  inputs=[input_source, upload_image, camera_image, colormap_choice],
259
+ outputs=[output_image, download_btn],
260
  show_progress=True
261
  )
262