xiank he commited on
Commit
ecb2ac2
·
1 Parent(s): 3d0ac0e

distill-any-depth

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -8,7 +8,8 @@ from distillanydepth.midas.transforms import Resize, NormalizeImage, PrepareForN
8
  from torchvision.transforms import Compose
9
  import cv2
10
  from huggingface_hub import hf_hub_download
11
- from safetensors.torch import load_file # 导入 safetensors 库
 
12
 
13
  # Helper function to load model from Hugging Face
14
  def load_model_by_name(arch_name, checkpoint_path, device):
@@ -70,7 +71,8 @@ def process_image(image, model, device):
70
  depth_image = Image.fromarray(depth_colored_hwc)
71
  return depth_image
72
 
73
- # Gradio interface function
 
74
  def gradio_interface(image):
75
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
76
 
@@ -114,7 +116,7 @@ iface = gr.Interface(
114
  inputs=gr.Image(type="pil"), # Only image input, no mode selection
115
  outputs=gr.Image(type="pil"), # Only depth image output, no debug info
116
  title="Depth Estimation Demo",
117
- description="Upload an image to see the depth estimation results. Our model is running on CPU, so it may take a while like ~80 seconds to process."
118
  )
119
 
120
  # Launch the Gradio interface
 
8
  from torchvision.transforms import Compose
9
  import cv2
10
  from huggingface_hub import hf_hub_download
11
+ from safetensors.torch import load_file
12
+ import spaces
13
 
14
  # Helper function to load model from Hugging Face
15
  def load_model_by_name(arch_name, checkpoint_path, device):
 
71
  depth_image = Image.fromarray(depth_colored_hwc)
72
  return depth_image
73
 
74
+ # Gradio interface function with GPU support
75
+ @spaces.GPU
76
  def gradio_interface(image):
77
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
78
 
 
116
  inputs=gr.Image(type="pil"), # Only image input, no mode selection
117
  outputs=gr.Image(type="pil"), # Only depth image output, no debug info
118
  title="Depth Estimation Demo",
119
+ description="Upload an image to see the depth estimation results. Our model is running on GPU for faster processing."
120
  )
121
 
122
  # Launch the Gradio interface