udbhav commited on
Commit
ca34b49
·
1 Parent(s): 0fc713e

added multi user

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -108,9 +108,19 @@ def _load_private_app_once():
108
  cache_dir = setup_environment()
109
  repo_path = download_private_repo(cache_dir, repo_id, hf_token)
110
 
111
- sys.path.insert(0, str(repo_path))
112
  try:
113
- import app as private_app
 
 
 
 
 
 
 
 
 
 
114
  # If the private app exposes a thumbnail generator, run it once
115
  # so example images are ready even when we bypass its main().
116
  try:
@@ -145,6 +155,10 @@ def _load_private_app_once():
145
  else:
146
  raise RuntimeError("No demo/app/create_app found in private repo")
147
 
 
 
 
 
148
  _PRIVATE_APP_CACHE = (private_app, repo_path)
149
  return _PRIVATE_APP_CACHE, _PRIVATE_APP_CREATE_APP
150
  except Exception as e:
 
108
  cache_dir = setup_environment()
109
  repo_path = download_private_repo(cache_dir, repo_id, hf_token)
110
 
111
+ # Import from repo_path directly using importlib to avoid importing wrapper's app.py
112
  try:
113
+ import importlib.util
114
+ app_file_path = os.path.join(repo_path, "app.py")
115
+ if not os.path.exists(app_file_path):
116
+ raise FileNotFoundError(f"app.py not found in {repo_path}")
117
+
118
+ spec = importlib.util.spec_from_file_location("private_app_module", app_file_path)
119
+ if spec is None or spec.loader is None:
120
+ raise ImportError(f"Could not load spec from {app_file_path}")
121
+
122
+ private_app = importlib.util.module_from_spec(spec)
123
+ spec.loader.exec_module(private_app)
124
  # If the private app exposes a thumbnail generator, run it once
125
  # so example images are ready even when we bypass its main().
126
  try:
 
155
  else:
156
  raise RuntimeError("No demo/app/create_app found in private repo")
157
 
158
+ # Also add repo_path to sys.path for any relative imports the private app might need
159
+ if str(repo_path) not in sys.path:
160
+ sys.path.insert(0, str(repo_path))
161
+
162
  _PRIVATE_APP_CACHE = (private_app, repo_path)
163
  return _PRIVATE_APP_CACHE, _PRIVATE_APP_CREATE_APP
164
  except Exception as e: