Tohru127 commited on
Commit
3e0ba7c
·
verified ·
1 Parent(s): f524e6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  """
2
  Insta360 3D Reconstruction - Hugging Face Space Version
3
  Optimized for longer videos with intelligent frame sampling
 
4
  """
5
 
6
  import gradio as gr
@@ -17,6 +18,7 @@ import time
17
  import warnings
18
  from scipy import ndimage
19
  from scipy.ndimage import gaussian_filter
 
20
 
21
  warnings.filterwarnings('ignore')
22
 
@@ -25,13 +27,9 @@ print("🔄 Loading depth estimation model...")
25
  try:
26
  dpt_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
27
  dpt_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
28
- if torch.cuda.is_available():
29
- dpt_model = dpt_model.cuda()
30
- print("✓ GPU detected and enabled")
31
- else:
32
- print("ℹ Running on CPU (slower but works)")
33
  dpt_model.eval()
34
- print("✅ Model loaded successfully!")
35
  except Exception as e:
36
  print(f"❌ Error loading model: {e}")
37
  dpt_processor = None
@@ -198,13 +196,12 @@ def equirectangular_to_perspective(equirect_img, fov=90, theta=0, phi=0, height=
198
 
199
  return perspective_img
200
 
 
201
  def estimate_depth_enhanced(image, processor, model):
202
  """Enhanced depth estimation with multi-scale processing"""
203
  inputs = processor(images=image, return_tensors="pt")
204
 
205
- if torch.cuda.is_available():
206
- inputs = {k: v.cuda() for k, v in inputs.items()}
207
-
208
  with torch.no_grad():
209
  outputs = model(**inputs)
210
  predicted_depth = outputs.predicted_depth
@@ -590,4 +587,4 @@ with gr.Blocks(title="Insta360 3D Reconstruction", theme=gr.themes.Soft()) as de
590
  """)
591
 
592
  if __name__ == "__main__":
593
- demo.launch()
 
1
  """
2
  Insta360 3D Reconstruction - Hugging Face Space Version
3
  Optimized for longer videos with intelligent frame sampling
4
+ Supports ZeroGPU for faster processing
5
  """
6
 
7
  import gradio as gr
 
18
  import warnings
19
  from scipy import ndimage
20
  from scipy.ndimage import gaussian_filter
21
+ import spaces # For ZeroGPU support
22
 
23
  warnings.filterwarnings('ignore')
24
 
 
27
  try:
28
  dpt_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
29
  dpt_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
30
+ # Don't move to CUDA here - ZeroGPU will handle it in decorated functions
 
 
 
 
31
  dpt_model.eval()
32
+ print("✅ Model loaded successfully! (ZeroGPU will handle GPU allocation)")
33
  except Exception as e:
34
  print(f"❌ Error loading model: {e}")
35
  dpt_processor = None
 
196
 
197
  return perspective_img
198
 
199
+ @spaces.GPU # ZeroGPU decorator for GPU acceleration
200
  def estimate_depth_enhanced(image, processor, model):
201
  """Enhanced depth estimation with multi-scale processing"""
202
  inputs = processor(images=image, return_tensors="pt")
203
 
204
+ # ZeroGPU automatically handles device placement
 
 
205
  with torch.no_grad():
206
  outputs = model(**inputs)
207
  predicted_depth = outputs.predicted_depth
 
587
  """)
588
 
589
  if __name__ == "__main__":
590
+ demo.launch()