Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,32 @@ from image_segmenter import ImageSegmenter
|
|
| 11 |
from monocular_depth_estimator import MonocularDepthEstimator
|
| 12 |
from point_cloud_generator import display_pcd
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# params
|
| 15 |
CANCEL_PROCESSING = False
|
| 16 |
|
|
@@ -186,4 +212,4 @@ if __name__ == "__main__":
|
|
| 186 |
conf_thres_vid.change(update_confidence_threshold, conf_thres_vid, [])
|
| 187 |
|
| 188 |
|
| 189 |
-
my_app.queue(
|
|
|
|
| 11 |
from monocular_depth_estimator import MonocularDepthEstimator
|
| 12 |
from point_cloud_generator import display_pcd
|
| 13 |
|
| 14 |
+
import os
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
# Disable NVML initialization to avoid errors in Hugging Face Spaces
|
| 18 |
+
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
|
| 19 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = ""
|
| 20 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "0" if torch.cuda.is_available() else "-1"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Ensure CUDA is properly initialized
|
| 24 |
+
try:
|
| 25 |
+
if torch.cuda.is_available():
|
| 26 |
+
print(f"✅ CUDA is available: {torch.cuda.get_device_name(0)}")
|
| 27 |
+
torch.cuda.init()
|
| 28 |
+
torch.cuda.empty_cache()
|
| 29 |
+
device = torch.device("cuda")
|
| 30 |
+
else:
|
| 31 |
+
print("❌ No CUDA available. Falling back to CPU.")
|
| 32 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
| 33 |
+
device = torch.device("cpu")
|
| 34 |
+
except RuntimeError as e:
|
| 35 |
+
print(f"🚨 CUDA initialization failed: {e}. Switching to CPU mode.")
|
| 36 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
| 37 |
+
device = torch.device("cpu")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
# params
|
| 41 |
CANCEL_PROCESSING = False
|
| 42 |
|
|
|
|
| 212 |
conf_thres_vid.change(update_confidence_threshold, conf_thres_vid, [])
|
| 213 |
|
| 214 |
|
| 215 |
+
my_app.queue(max_size=20).launch()
|