Skip to content

Commit 1bbf7cd

Browse files
committed
🔧 refactor: reformat load_model function for readability
- Adjusted parameter alignment in `load_model` definition - Refactored `load_large_model` logic for clarity - Enhanced fallback logic for strict and non-strict modes
1 parent ba4e9d7 commit 1bbf7cd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/fast_langdetect/ft_detect/infer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,18 @@ def load_large_model():
9191
return load_local_small_model()
9292

9393
# Path for the large model
94-
model_path = Path(CACHE_DIRECTORY) / "lid.176.bin"
94+
large_model_name = "lid.176.bin"
95+
model_path = Path(CACHE_DIRECTORY) / large_model_name
9596

97+
# If the large model is already present, load it
9698
if model_path.exists():
99+
# Model cant be dir
100+
if model_path.is_dir():
101+
try:
102+
model_path.rmdir()
103+
except Exception as e:
104+
logger.error(f"Failed to remove the directory '{model_path}': {e}")
105+
raise DetectError(f"Unexpected directory found in large model file path '{model_path}': {e}")
97106
# Attempt to load large model
98107
loaded_model = load_large_model()
99108
if loaded_model:
@@ -106,7 +115,7 @@ def load_large_model():
106115
download(
107116
url=model_url,
108117
folder=CACHE_DIRECTORY,
109-
filename="lid.176.bin",
118+
filename=large_model_name,
110119
proxy=download_proxy,
111120
retry_max=3,
112121
timeout=20

0 commit comments

Comments
 (0)