smajumdar commited on
Commit
a8ddd76
1 Parent(s): c676622

Prevent preallocation of gradio interface, do it at runtime

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -95,8 +95,8 @@ SUPPORTED_MODEL_NAMES = sorted(list(SUPPORTED_MODEL_NAMES))
95
  model_dict = {}
96
  for model_name in SUPPORTED_MODEL_NAMES:
97
  try:
98
- iface = gr.Interface.load(f'models/{model_name}')
99
- model_dict[model_name] = iface
100
  except:
101
  pass
102
 
@@ -370,6 +370,17 @@ def infer_audio(model_name: str, audio_file: str) -> str:
370
  # Obtain Gradio Model function from cache of models
371
  if model_name in model_dict:
372
  model = model_dict[model_name]
 
 
 
 
 
 
 
 
 
 
 
373
  else:
374
  model = None
375
 
 
95
  model_dict = {}
96
  for model_name in SUPPORTED_MODEL_NAMES:
97
  try:
98
+ # iface = gr.Interface.load(f'models/{model_name}')
99
+ model_dict[model_name] = None
100
  except:
101
  pass
102
 
 
370
  # Obtain Gradio Model function from cache of models
371
  if model_name in model_dict:
372
  model = model_dict[model_name]
373
+
374
+ if model is None:
375
+ # Load the gradio interface
376
+ try:
377
+ iface = gr.Interface.load(f'models/{model_name}')
378
+ except:
379
+ iface = None
380
+
381
+ if iface is not None:
382
+ # Update model cache
383
+ model_dict[model_name] = iface
384
  else:
385
  model = None
386