|
24 | 24 | import tkinter as tk |
25 | 25 | from tkinter import ttk , messagebox |
26 | 26 | import threading |
27 | | -import os |
28 | | -import glob |
| 27 | +from pathlib import Path |
29 | 28 | import UI.Helpers |
30 | 29 | from Model import Model, ModelManager |
31 | 30 | from services.whisper_hallucination_cleaner import load_hallucination_cleaner_model |
@@ -582,53 +581,19 @@ def get_selected_model(self): |
582 | 581 | return self.models_drop_down.get() |
583 | 582 |
|
584 | 583 | def _get_local_model_options(self): |
585 | | - """ |
586 | | - Scans the ./models folder for LLM model files and returns a list of options. |
587 | | - |
588 | | - Returns: |
589 | | - list: List of model file names found in ./models folder, plus "Custom" option |
590 | | - """ |
591 | | - |
592 | | - models_folder = os.path.join(os.getcwd(), "models") |
593 | | - model_options = [] |
594 | | - |
595 | | - # Common LLM model file extensions |
596 | | - model_extensions = [ |
597 | | - "*.gguf", # GGUF format (llama.cpp) |
598 | | - "*.safetensors", # SafeTensors format |
599 | | - "*.bin", # PyTorch binary format |
600 | | - ] |
601 | | - |
602 | | - try: |
603 | | - if os.path.exists(models_folder): |
604 | | - # Scan for all supported model file types |
605 | | - for extension in model_extensions: |
606 | | - pattern = os.path.join(models_folder, "**", extension) |
607 | | - found_files = glob.glob(pattern, recursive=True) |
608 | | - |
609 | | - for file_path in found_files: |
610 | | - # Get relative path from models folder |
611 | | - rel_path = os.path.relpath(file_path, models_folder) |
612 | | - if rel_path not in model_options: |
613 | | - model_options.append(f"./models/{rel_path}") |
614 | | - |
615 | | - # Sort the model options alphabetically |
616 | | - model_options.sort() |
617 | | - |
618 | | - else: |
619 | | - logger.warning(f"Models folder not found: {models_folder}") |
620 | | - |
621 | | - except Exception as e: |
622 | | - logger.error(f"Error scanning models folder: {e}") |
623 | | - |
624 | | - # Add "Custom" option at the end |
625 | | - model_options.append("Custom") |
626 | | - |
627 | | - # If no models found, add a placeholder |
628 | | - if len(model_options) == 1: # Only "Custom" option |
629 | | - model_options.insert(0, "No models found") |
630 | | - |
631 | | - return model_options |
| 584 | + root = Path.cwd() / "models" |
| 585 | + exts = ["*.gguf", "*.safetensors", "*.bin"] |
| 586 | + options = sorted({ |
| 587 | + f"./models/{p.relative_to(root)}" |
| 588 | + for ext in exts |
| 589 | + for p in root.rglob(ext) |
| 590 | + }) if root.exists() else [] |
| 591 | + |
| 592 | + if not options: |
| 593 | + options = ["No models found"] |
| 594 | + |
| 595 | + options.append("Custom") |
| 596 | + return options |
632 | 597 |
|
633 | 598 | def create_editable_settings_col(self, left_frame, right_frame, left_row, right_row, settings_set): |
634 | 599 | """ |
|
0 commit comments