Skip to content

Commit b78a51f

Browse files
committed
changed os.path in pathlib during model loading
1 parent 9d93811 commit b78a51f

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

modules/path.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
2+
from pathlib import Path
33
import json
44

55
from os.path import exists
@@ -70,29 +70,24 @@ def get_abspath(path):
7070

7171

7272
def get_model_filenames(folder_path, isLora=False):
73-
if not os.path.isdir(folder_path):
73+
folder_path = Path(folder_path)
74+
if not folder_path.is_dir():
7475
raise ValueError("Folder path is not a valid directory.")
7576

7677
filenames = []
7778

78-
for root, dirs, files in os.walk(folder_path):
79-
relative_path = os.path.relpath(root, folder_path)
80-
if relative_path == ".":
81-
relative_path = ""
82-
for filename in files:
83-
_, ext = os.path.splitext(filename)
84-
if ext.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]:
85-
path = os.path.join(relative_path, filename)
86-
if isLora:
87-
txtcheck = path.replace(".safetensors", ".txt")
88-
if os.path.isfile(f"{folder_path}{txtcheck}"):
89-
path = path + " 🗒️"
90-
91-
filenames.append(path)
79+
for path in folder_path.rglob("*"):
80+
if path.suffix.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]:
81+
if isLora:
82+
txtcheck = path.with_suffix(".txt")
83+
if txtcheck.exists():
84+
path = path.with_suffix(f"{path.suffix} 🗒️")
85+
86+
filenames.append(str(path.relative_to(folder_path)))
9287

9388
return sorted(
9489
filenames,
95-
key=lambda x: f"0{x.casefold()}" if os.sep in x else f"1{x.casefold()}",
90+
key=lambda x: f"0{x.casefold()}" if Path(x).suffix in x else f"1{x.casefold()}",
9691
)
9792

9893

update_log.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.25.2
2+
* Fixed an os.path issue by replaceing with pathlib
3+
14
### 1.25.1
25
* Now displays 🗒️ at the end of the loraname if it has a keyword .txt file
36

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.25.1"
1+
version = "1.25.2"

0 commit comments

Comments
 (0)