Spaces:
Sleeping
Sleeping
David Ko
commited on
Commit
ยท
44253a0
1
Parent(s):
e821ec3
Fix: YOLOv8 model download permission issues using temp directory
Browse files
api.py
CHANGED
@@ -23,14 +23,35 @@ try:
|
|
23 |
import os
|
24 |
from ultralytics import YOLO
|
25 |
|
26 |
-
# ๋ชจ๋ธ ํ์ผ ๊ฒฝ๋ก
|
27 |
-
|
|
|
|
|
28 |
|
29 |
# ๋ชจ๋ธ ํ์ผ์ด ์์ผ๋ฉด ์ง์ ๋ค์ด๋ก๋
|
30 |
if not os.path.exists(model_path):
|
31 |
-
print("Downloading YOLOv8 model...")
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
yolo_model = YOLO(model_path) # Using the nano model for faster inference
|
36 |
print("YOLOv8 model loaded successfully")
|
|
|
23 |
import os
|
24 |
from ultralytics import YOLO
|
25 |
|
26 |
+
# ๋ชจ๋ธ ํ์ผ ๊ฒฝ๋ก - ์์ ๋๋ ํ ๋ฆฌ ์ฌ์ฉ
|
27 |
+
import tempfile
|
28 |
+
temp_dir = tempfile.gettempdir()
|
29 |
+
model_path = os.path.join(temp_dir, "yolov8n.pt")
|
30 |
|
31 |
# ๋ชจ๋ธ ํ์ผ์ด ์์ผ๋ฉด ์ง์ ๋ค์ด๋ก๋
|
32 |
if not os.path.exists(model_path):
|
33 |
+
print(f"Downloading YOLOv8 model to {model_path}...")
|
34 |
+
try:
|
35 |
+
os.system(f"wget -q https://ultralytics.com/assets/yolov8n.pt -O {model_path}")
|
36 |
+
print("YOLOv8 model downloaded successfully")
|
37 |
+
except Exception as e:
|
38 |
+
print(f"Error downloading YOLOv8 model: {e}")
|
39 |
+
# ๋ค์ด๋ก๋ ์คํจ ์ ๋์ฒด URL ์๋
|
40 |
+
try:
|
41 |
+
os.system(f"wget -q https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt -O {model_path}")
|
42 |
+
print("YOLOv8 model downloaded from alternative source")
|
43 |
+
except Exception as e2:
|
44 |
+
print(f"Error downloading from alternative source: {e2}")
|
45 |
+
# ๋ง์ง๋ง ๋์์ผ๋ก ์ง์ ๋ชจ๋ธ URL ์ฌ์ฉ
|
46 |
+
try:
|
47 |
+
os.system(f"curl -L https://ultralytics.com/assets/yolov8n.pt --output {model_path}")
|
48 |
+
print("YOLOv8 model downloaded using curl")
|
49 |
+
except Exception as e3:
|
50 |
+
print(f"All download attempts failed: {e3}")
|
51 |
+
|
52 |
+
# ํ๊ฒฝ ๋ณ์ ์ค์ - ์ค์ ํ์ผ ๊ฒฝ๋ก ์ง์
|
53 |
+
os.environ["YOLO_CONFIG_DIR"] = temp_dir
|
54 |
+
os.environ["MPLCONFIGDIR"] = temp_dir
|
55 |
|
56 |
yolo_model = YOLO(model_path) # Using the nano model for faster inference
|
57 |
print("YOLOv8 model loaded successfully")
|