Yhhxhfh commited on
Commit
9b9825b
1 Parent(s): f8544e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -37,13 +37,14 @@ global_data = {
37
  class ModelManager:
38
  def __init__(self):
39
  self.models = {}
40
- self.load_all_models()
41
-
42
- def load_all_models(self):
43
- with ThreadPoolExecutor(max_workers=len(global_data['model_configs'])) as executor:
44
- futures = [executor.submit(self._load_model, config) for config in tqdm(global_data['model_configs'], desc="Loading models")]
45
- for future in tqdm(as_completed(futures), total=len(global_data['model_configs']), desc="Loading models complete"):
46
- future.result()
 
47
 
48
  def _load_model(self, model_config):
49
  model_name = model_config['name']
 
37
  class ModelManager:
38
  def __init__(self):
39
  self.models = {}
40
+ self.load_models_once()
41
+
42
+ def load_models_once(self):
43
+ if not self.models: # Load models only once
44
+ with ThreadPoolExecutor(max_workers=len(global_data['model_configs'])) as executor:
45
+ futures = [executor.submit(self._load_model, config) for config in tqdm(global_data['model_configs'], desc="Loading models")]
46
+ for future in tqdm(as_completed(futures), total=len(global_data['model_configs']), desc="Loading models complete"):
47
+ future.result()
48
 
49
  def _load_model(self, model_config):
50
  model_name = model_config['name']