7
7
import concurrent .futures
8
8
import time
9
9
import os
10
+ import re
10
11
from tqdm import tqdm
11
12
import platform
12
13
import tempfile
23
24
NEXA_RUN_MODEL_MAP ,
24
25
NEXA_TOKEN_PATH ,
25
26
NEXA_OFFICIAL_MODELS_TYPE ,
27
+ NEXA_LIST_FILTERED_MODEL_PREFIXES
26
28
)
27
29
from nexa .constants import ModelType
28
30
@@ -679,17 +681,13 @@ def add_model_to_list(model_name, model_location, model_type, run_type):
679
681
if tag_name .startswith ("model-" ):
680
682
tag_name = tag_name [6 :]
681
683
model_name = f"{ model_name .split (':' )[0 ]} :{ tag_name } "
682
- else :
683
- return
684
684
685
685
# For Computer Vision Flux model, should remove the "flux1-schnell-" prefix from the tag name
686
686
if run_type == "Computer Vision" :
687
687
tag_name = model_name .split (":" )[1 ]
688
688
if tag_name .startswith ("flux1-schnell-" ):
689
689
tag_name = tag_name [14 :]
690
690
model_name = f"{ model_name .split (':' )[0 ]} :{ tag_name } "
691
- else :
692
- return
693
691
694
692
model_list [model_name ] = {
695
693
"type" : model_type ,
@@ -737,7 +735,8 @@ def list_models():
737
735
filtered_list = {
738
736
model_name : model_info
739
737
for model_name , model_info in model_list .items ()
740
- if ':' not in model_name or not model_name .split (':' )[1 ].startswith ('projector' )
738
+ if ':' not in model_name or
739
+ not any (model_name .split (':' )[1 ].startswith (prefix ) for prefix in NEXA_LIST_FILTERED_MODEL_PREFIXES )
741
740
}
742
741
743
742
table = [
@@ -812,7 +811,7 @@ def remove_model(model_path):
812
811
else :
813
812
print (f"Warning: Model location not found: { model_path } " )
814
813
815
- # Delete projectors only if model was successfully deleted
814
+ # Delete projectors or flux related files only if model was successfully deleted
816
815
if model_deleted :
817
816
parent_dir = model_path .parent
818
817
gguf_files = list (parent_dir .glob ("*.gguf" ))
@@ -834,6 +833,46 @@ def remove_model(model_path):
834
833
shutil .rmtree (projector_location )
835
834
print (f"Deleted projector: { projector_location } " )
836
835
836
+ # Check if the model path contains "flux"
837
+ if 'flux' in str (model_path ).lower ():
838
+ model_path_parts = str (model_path ).split (":" )
839
+ tag_name = None
840
+
841
+ for part in model_path_parts :
842
+ match = re .search (r'q\d_|fp16' , part )
843
+ if match :
844
+ tag_name = part [match .start ():]
845
+ break
846
+ else :
847
+ raise ValueError (
848
+ "Invalid model path. Expected a tag name in the model path." )
849
+
850
+ if tag_name :
851
+ # First delete files matching tag_name
852
+ for item in parent_dir .glob (f"*{ tag_name } *" ):
853
+ if item .exists ():
854
+ if item .is_file ():
855
+ item .unlink ()
856
+ else :
857
+ shutil .rmtree (item )
858
+ print (f"Deleted flux-related file: { item } " )
859
+
860
+ # Check remaining files: ae- and clip_l- files
861
+ remaining_files = list (parent_dir .glob ("*" ))
862
+ if len (remaining_files ) == 2 :
863
+ file_names = [f .name .lower () for f in remaining_files ]
864
+ has_ae = any (name .startswith ("ae-" ) for name in file_names )
865
+ has_clip = any (name .startswith ("clip_l-" ) for name in file_names )
866
+
867
+ if has_ae and has_clip :
868
+ for item in remaining_files :
869
+ if item .exists ():
870
+ if item .is_file ():
871
+ item .unlink ()
872
+ else :
873
+ shutil .rmtree (item )
874
+ print (f"Deleted additional file: { item } " )
875
+
837
876
# Update the model list file
838
877
with open (NEXA_MODEL_LIST_PATH , "w" ) as f :
839
878
json .dump (model_list , f , indent = 2 )
0 commit comments