mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-01-20 23:50:30 +01:00
UI: show only part 00001 of multipart GGUF models in the model menu
This commit is contained in:
parent
bce1b68ca9
commit
9424ba17c8
|
|
@ -76,44 +76,54 @@ def get_available_models():
|
|||
# Get all GGUF files
|
||||
gguf_files = get_available_ggufs()
|
||||
|
||||
# Filter out non-first parts of multipart GGUF files
|
||||
filtered_gguf_files = []
|
||||
for gguf_path in gguf_files:
|
||||
filename = os.path.basename(gguf_path)
|
||||
|
||||
match = re.search(r'-(\d+)-of-\d+\.gguf$', filename)
|
||||
|
||||
if match:
|
||||
part_number = match.group(1)
|
||||
# Keep only if it's part 1
|
||||
if part_number.lstrip("0") == "1":
|
||||
filtered_gguf_files.append(gguf_path)
|
||||
else:
|
||||
# Not a multi-part file
|
||||
filtered_gguf_files.append(gguf_path)
|
||||
|
||||
model_dir = Path(shared.args.model_dir)
|
||||
|
||||
# Find top-level directories containing GGUF files
|
||||
dirs_with_gguf = set()
|
||||
for gguf_path in gguf_files:
|
||||
path = Path(gguf_path)
|
||||
if path.parts: # If in a subdirectory
|
||||
dirs_with_gguf.add(path.parts[0]) # Add top-level directory
|
||||
if path.parts:
|
||||
dirs_with_gguf.add(path.parts[0])
|
||||
|
||||
# Find directories with safetensors files directly under them
|
||||
# Find directories with safetensors files
|
||||
dirs_with_safetensors = set()
|
||||
for item in os.listdir(model_dir):
|
||||
item_path = model_dir / item
|
||||
if item_path.is_dir():
|
||||
# Check if there are safetensors files directly under this directory
|
||||
if any(file.lower().endswith(('.safetensors', '.pt')) for file in os.listdir(item_path) if (item_path / file).is_file()):
|
||||
dirs_with_safetensors.add(item)
|
||||
|
||||
# Find valid model directories
|
||||
model_dirs = []
|
||||
|
||||
for item in os.listdir(model_dir):
|
||||
item_path = model_dir / item
|
||||
|
||||
# Skip if not a directory
|
||||
if not item_path.is_dir():
|
||||
continue
|
||||
|
||||
# Include directory if it either:
|
||||
# 1. Doesn't contain GGUF files, OR
|
||||
# 2. Contains both GGUF and safetensors files
|
||||
# Include directory if it either doesn't contain GGUF files
|
||||
# or contains both GGUF and safetensors files
|
||||
if item not in dirs_with_gguf or item in dirs_with_safetensors:
|
||||
model_dirs.append(item)
|
||||
|
||||
model_dirs = sorted(model_dirs, key=natural_keys)
|
||||
|
||||
# Combine all models
|
||||
return ['None'] + gguf_files + model_dirs
|
||||
return ['None'] + filtered_gguf_files + model_dirs
|
||||
|
||||
|
||||
def get_available_ggufs():
|
||||
|
|
|
|||
Loading…
Reference in a new issue