charliebaby2023 commited on
Commit
8642b09
·
verified ·
1 Parent(s): 426fdd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.py CHANGED
@@ -8,6 +8,7 @@ import numpy as np
8
  import time
9
  import requests
10
  import logging
 
11
 
12
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
13
  logging.basicConfig(level=logging.WARNING)
@@ -36,19 +37,42 @@ def sanitize_file_name(file_name, max_length=100):
36
 
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  def load_fn(models):
40
- global models_load
41
- models_load = {}
42
  for model in models:
43
- if model not in models_load.keys():
44
- try:
45
- m = gr.load(f'models/{model}')
46
- print(f"{m}\n");
47
- except Exception as error:
48
- print(f"Error loading model {model}: {error}\n")
49
- m = gr.Interface(lambda _: None, inputs=gr.Textbox(), outputs=gr.Image(), queue=False)
50
- models_load.update({model: m})
 
 
 
 
 
 
 
 
 
51
 
 
52
 
53
  load_fn(models)
54
  num_models = len(models)
 
8
  import time
9
  import requests
10
  import logging
11
+ import traceback # For better error reporting
12
 
13
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
14
  logging.basicConfig(level=logging.WARNING)
 
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)