ysharma HF staff commited on
Commit
ae35a71
·
verified ·
1 Parent(s): bb0bf83

added imagelslider and examples with caching

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -9,6 +9,7 @@ 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
@@ -69,7 +70,7 @@ def process_image(image, model, device):
69
 
70
  # Convert to a PIL image
71
  depth_image = Image.fromarray(depth_colored_hwc)
72
- return depth_image
73
 
74
  # Gradio interface function with GPU support
75
  @spaces.GPU
@@ -114,10 +115,11 @@ def gradio_interface(image):
114
  iface = gr.Interface(
115
  fn=gradio_interface,
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
123
  iface.launch()
 
9
  import cv2
10
  from huggingface_hub import hf_hub_download
11
  from safetensors.torch import load_file
12
+ from gradio_imageslider import ImageSlider
13
  import spaces
14
 
15
  # Helper function to load model from Hugging Face
 
70
 
71
  # Convert to a PIL image
72
  depth_image = Image.fromarray(depth_colored_hwc)
73
+ return image, depth_image
74
 
75
  # Gradio interface function with GPU support
76
  @spaces.GPU
 
115
  iface = gr.Interface(
116
  fn=gradio_interface,
117
  inputs=gr.Image(type="pil"), # Only image input, no mode selection
118
+ outputs = ImageSlider(label="Depth slider", type="pil", slider_color="pink"), # Depth image out with a slider
119
  title="Depth Estimation Demo",
120
+ description="Upload an image to see the depth estimation results. Our model is running on GPU for faster processing.",
121
+ examples=["maizi.jpg", "hair.jpg", "videoframe_10273.png", "videoframe_2168.png", "videoframe_3289.png"],
122
+ cache_examples=True,)
123
 
124
  # Launch the Gradio interface
125
  iface.launch()