Skip to content

Commit

Permalink
changed os.path in pathlib during model loading
Browse files Browse the repository at this point in the history
  • Loading branch information
runew0lf committed Dec 8, 2023
1 parent 9d93811 commit b78a51f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
29 changes: 12 additions & 17 deletions modules/path.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

from pathlib import Path
import json

from os.path import exists
Expand Down Expand Up @@ -70,29 +70,24 @@ def get_abspath(path):


def get_model_filenames(folder_path, isLora=False):
if not os.path.isdir(folder_path):
folder_path = Path(folder_path)
if not folder_path.is_dir():
raise ValueError("Folder path is not a valid directory.")

filenames = []

for root, dirs, files in os.walk(folder_path):
relative_path = os.path.relpath(root, folder_path)
if relative_path == ".":
relative_path = ""
for filename in files:
_, ext = os.path.splitext(filename)
if ext.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]:
path = os.path.join(relative_path, filename)
if isLora:
txtcheck = path.replace(".safetensors", ".txt")
if os.path.isfile(f"{folder_path}{txtcheck}"):
path = path + " 🗒️"

filenames.append(path)
for path in folder_path.rglob("*"):
if path.suffix.lower() in [".pth", ".ckpt", ".bin", ".safetensors"]:
if isLora:
txtcheck = path.with_suffix(".txt")
if txtcheck.exists():
path = path.with_suffix(f"{path.suffix} 🗒️")

filenames.append(str(path.relative_to(folder_path)))

return sorted(
filenames,
key=lambda x: f"0{x.casefold()}" if os.sep in x else f"1{x.casefold()}",
key=lambda x: f"0{x.casefold()}" if Path(x).suffix in x else f"1{x.casefold()}",
)


Expand Down
3 changes: 3 additions & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.25.2
* Fixed an os.path issue by replaceing with pathlib

### 1.25.1
* Now displays 🗒️ at the end of the loraname if it has a keyword .txt file

Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.25.1"
version = "1.25.2"

0 comments on commit b78a51f

Please sign in to comment.