adpro commited on
Commit
375761e
·
verified ·
1 Parent(s): a829b1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import io
2
  import os
 
3
  import time
4
  import numpy as np
5
  import cv2
@@ -11,17 +12,21 @@ import uvicorn
11
 
12
  app = FastAPI()
13
 
14
- # 🟢 Cài đặt ZoeDepth từ Hugging Face (chạy trên lần đầu)
15
- if not os.path.exists("ZoeDepth"):
 
16
  os.system("git clone https://github.com/isl-org/ZoeDepth.git")
17
 
18
- # 🟢 Import ZoeDepth sau khi clone
19
- from ZoeDepth.zoedepth.models.builder import build_model
20
- from ZoeDepth.zoedepth.utils.config import get_config
 
 
 
21
 
22
  # 🟢 Load mô hình ZoeDepth-Tiny
23
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
24
- config = get_config("ZoeDepth/configs/zoedepth_tiny.py") # 🟢 Chọn model tiny để chạy nhanh hơn
25
  model = build_model(config).to(device)
26
  model.eval()
27
 
 
1
  import io
2
  import os
3
+ import sys
4
  import time
5
  import numpy as np
6
  import cv2
 
12
 
13
  app = FastAPI()
14
 
15
+ # 🟢 Kiểm tra nếu ZoeDepth chưa được tải, thì tải về
16
+ zoe_path = "ZoeDepth"
17
+ if not os.path.exists(zoe_path):
18
  os.system("git clone https://github.com/isl-org/ZoeDepth.git")
19
 
20
+ # 🟢 Thêm ZoeDepth vào sys.path để import được
21
+ sys.path.append(os.path.abspath(zoe_path))
22
+
23
+ # 🟢 Import ZoeDepth sau khi đã tải về
24
+ from zoedepth.models.builder import build_model
25
+ from zoedepth.utils.config import get_config
26
 
27
  # 🟢 Load mô hình ZoeDepth-Tiny
28
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
29
+ config = get_config(f"{zoe_path}/configs/zoedepth_tiny.py") # 🟢 Chọn model tiny để chạy nhanh hơn
30
  model = build_model(config).to(device)
31
  model.eval()
32