Spaces:
Build error
Build error
Update prepare.py
Browse files- prepare.py +30 -30
prepare.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
from huggingface_hub import hf_hub_download
|
| 2 |
-
import shutil
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
# Hugging Face model details
|
| 6 |
-
REPO_ID = "
|
| 7 |
-
MODEL_FILENAME = "model.h5"
|
| 8 |
-
LABEL_JSON = "class.json"
|
| 9 |
-
|
| 10 |
-
def download_file(repo_id, filename, dest_filename):
|
| 11 |
-
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 12 |
-
|
| 13 |
-
# Get the absolute path of the actual file (resolves symlinks)
|
| 14 |
-
real_file_path = os.path.realpath(file_path)
|
| 15 |
-
|
| 16 |
-
# Ensure the resolved file exists before copying
|
| 17 |
-
if not os.path.exists(real_file_path):
|
| 18 |
-
raise FileNotFoundError(f"Resolved file path does not exist: {real_file_path}")
|
| 19 |
-
|
| 20 |
-
# Copy the actual file to the destination
|
| 21 |
-
shutil.copy2(real_file_path, dest_filename)
|
| 22 |
-
os.remove(real_file_path)
|
| 23 |
-
|
| 24 |
-
# Download model if not present
|
| 25 |
-
if not os.path.exists(MODEL_FILENAME):
|
| 26 |
-
download_file(REPO_ID, MODEL_FILENAME, MODEL_FILENAME)
|
| 27 |
-
|
| 28 |
-
# Download label JSON if not present
|
| 29 |
-
if not os.path.exists(LABEL_JSON):
|
| 30 |
-
download_file(REPO_ID, LABEL_JSON, LABEL_JSON)
|
|
|
|
| 1 |
+
from huggingface_hub import hf_hub_download
|
| 2 |
+
import shutil
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Hugging Face model details
|
| 6 |
+
REPO_ID = "riciii7/KCVanguard"
|
| 7 |
+
MODEL_FILENAME = "model.h5"
|
| 8 |
+
LABEL_JSON = "class.json"
|
| 9 |
+
|
| 10 |
+
def download_file(repo_id, filename, dest_filename):
|
| 11 |
+
file_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 12 |
+
|
| 13 |
+
# Get the absolute path of the actual file (resolves symlinks)
|
| 14 |
+
real_file_path = os.path.realpath(file_path)
|
| 15 |
+
|
| 16 |
+
# Ensure the resolved file exists before copying
|
| 17 |
+
if not os.path.exists(real_file_path):
|
| 18 |
+
raise FileNotFoundError(f"Resolved file path does not exist: {real_file_path}")
|
| 19 |
+
|
| 20 |
+
# Copy the actual file to the destination
|
| 21 |
+
shutil.copy2(real_file_path, dest_filename)
|
| 22 |
+
os.remove(real_file_path)
|
| 23 |
+
|
| 24 |
+
# Download model if not present
|
| 25 |
+
if not os.path.exists(MODEL_FILENAME):
|
| 26 |
+
download_file(REPO_ID, MODEL_FILENAME, MODEL_FILENAME)
|
| 27 |
+
|
| 28 |
+
# Download label JSON if not present
|
| 29 |
+
if not os.path.exists(LABEL_JSON):
|
| 30 |
+
download_file(REPO_ID, LABEL_JSON, LABEL_JSON)
|