Skip to content

Commit

Permalink
refresh models list on start (#229)
Browse files Browse the repository at this point in the history
anti-frustration feature
  • Loading branch information
kabachuha authored Sep 3, 2023
1 parent 973186c commit 01e41fd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/t2v_helpers/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def setup_text2video_settings_dictionary():
with gr.Row(variant='compact'):
# TODO: deprecate this in favor of dynamic model type reading
model_type = gr.Radio(label='Model type', choices=['ModelScope', 'VideoCrafter (WIP)'], value='ModelScope', elem_id='model-type')
model = gr.Dropdown(label='Model', value="<modelscope>", help="Put the folders with models (configuration, vae, clip, diffusion model) in models/text2video. Each folder matches to a model. <modelscope> and <videocrafter> are the legacy locations")
refresh_models = ToolButton(value=refresh_symbol)

def refresh_all_models(model):
def get_models():
models = []
if os.path.isdir(os.path.join(ph.models_path, 'ModelScope/t2v')):
models.append('<modelscope>')
Expand All @@ -93,6 +90,17 @@ def refresh_all_models(model):
for subdir in os.listdir(models_dir):
if os.path.isdir(os.path.join(models_dir, subdir)):
models.append(subdir)
return models
try:
models = get_models()
except:
models = []
models = models if len(models) > 0 else ["<modelscope>"]
model = gr.Dropdown(label='Model', value=models[0], choices=models, help="Put the folders with models (configuration, vae, clip, diffusion model) in models/text2video. Each folder matches to a model. <modelscope> and <videocrafter> are the legacy locations")
refresh_models = ToolButton(value=refresh_symbol)

def refresh_all_models(model):
models = get_models()
return gr.update(value=model if model in models else None, choices=models, visible=True)

refresh_models.click(refresh_all_models, model, model)
Expand Down

0 comments on commit 01e41fd

Please sign in to comment.