MCPcopy
hub / github.com/modelscope/DiffSynth-Studio / download_models

Function download_models

diffsynth/models/downloader.py:72–111  ·  view source on GitHub ↗
(
    model_id_list: List[Preset_model_id] = [],
    downloading_priority: List[Preset_model_website] = ["ModelScope", "HuggingFace"],
)

Source from the content-addressed store, hash-verified

70
71
72def download_models(
73 model_id_list: List[Preset_model_id] = [],
74 downloading_priority: List[Preset_model_website] = ["ModelScope", "HuggingFace"],
75):
76 print(f"Downloading models: {model_id_list}")
77 downloaded_files = []
78 load_files = []
79
80 for model_id in model_id_list:
81 for website in downloading_priority:
82 if model_id in website_to_preset_models[website]:
83
84 # Parse model metadata
85 model_metadata = website_to_preset_models[website][model_id]
86 if isinstance(model_metadata, list):
87 file_data = model_metadata
88 else:
89 file_data = model_metadata.get("file_list", [])
90
91 # Try downloading the model from this website.
92 model_files = []
93 for model_id, origin_file_path, local_dir in file_data:
94 # Check if the file is downloaded.
95 file_to_download = os.path.join(local_dir, os.path.basename(origin_file_path))
96 if file_to_download in downloaded_files:
97 continue
98 # Download
99 website_to_download_fn[website](model_id, origin_file_path, local_dir)
100 if os.path.basename(origin_file_path) in os.listdir(local_dir):
101 downloaded_files.append(file_to_download)
102 model_files.append(file_to_download)
103
104 # If the model is successfully downloaded, break.
105 if len(model_files) > 0:
106 if isinstance(model_metadata, dict) and "load_path" in model_metadata:
107 model_files = model_metadata["load_path"]
108 load_files.extend(model_files)
109 break
110
111 return load_files

Calls

no outgoing calls

Tested by 3

generate_imageFunction · 0.72
generate_videoFunction · 0.72
upscale_videoFunction · 0.72