charliebaby2023 commited on
Commit
431834a
·
verified ·
1 Parent(s): 8642b09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -32
app.py CHANGED
@@ -37,42 +37,24 @@ def sanitize_file_name(file_name, max_length=100):
37
 
38
 
39
 
40
- #def load_fn(models):
41
- # global models_load
42
- # models_load = {}
43
- # for model in models:
44
- # if model not in models_load.keys():
45
- # try:
46
- # m = gr.load(f'models/{model}')
47
- # print(f"{m}\n");
48
- # except Exception as error:
49
- # print(f"Error loading model {model}: {error}\n")
50
- # m = gr.Interface(lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), queue=False)
51
- # models_load.update({model: m})
52
-
53
  def load_fn(models):
54
- models_load = {} # Dictionary to store loaded models
55
-
56
  for model in models:
57
- try:
58
- print(f"Attempting to load model: {model}") # Debugging print
59
-
60
- # Load model properly (replace this with your actual model-loading logic)
61
- # If `gr.load()` is incorrect for your use case, use a different loading method.
62
- m = gr.Interface.load(f'models/{model}') # Adjust as needed
63
-
64
- print(f"Successfully loaded model: {model}\n")
65
-
66
- except Exception as error:
67
- print(f"Error loading model {model}: {error}")
68
- traceback.print_exc() # Prints full error stack trace for debugging
69
-
70
- # Assign a dummy interface to avoid crashes
71
- #m = gr.Interface(fn=lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), queue=False)
72
- models_load[model] = None
73
  models_load[model] = m # Store in dictionary
74
 
75
- return models_load # Return dictionary instead of using global
76
 
77
  load_fn(models)
78
  num_models = len(models)
 
37
 
38
 
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def load_fn(models):
41
+ global models_load
42
+ models_load = {}
43
  for model in models:
44
+ if model not in models_load.keys():
45
+ try:
46
+ m = gr.load(f'models/{model}')
47
+ print(f"{m}\n");
48
+ except Exception as error:
49
+ print(f"Error loading model {model}: {error}\n")
50
+ m = gr.Interface(lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), queue=False)
51
+ models_load.update({model: m})
52
+ traceback.print_exc() # Prints full error stack trace for debugging
53
+ #m = gr.Interface(fn=lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), queue=False)
54
+ models_load[model] = None
 
 
 
 
 
55
  models_load[model] = m # Store in dictionary
56
 
57
+ #return models_load # Return dictionary instead of using global
58
 
59
  load_fn(models)
60
  num_models = len(models)