uhoui commited on
Commit
80dcbaf
·
1 Parent(s): 5d21a6b
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,16 +1,17 @@
1
  import subprocess
2
  import sys
 
3
 
4
- # List of dependencies you need
5
  deps = ["transformers", "torch", "fastapi", "uvicorn", "huggingface_hub", "accelerate"]
6
 
7
- # Attempt to install anything missing
8
  for dep in deps:
9
  try:
10
- __import__(dep)
11
  except ImportError:
12
  print(f"Installing missing dependency: {dep}")
13
  subprocess.check_call([sys.executable, "-m", "pip", "install", dep])
14
 
15
- # Now import the real server logic (split into another file)
16
- import main
 
 
1
  import subprocess
2
  import sys
3
+ import importlib
4
 
5
+ # List of dependencies to ensure are installed
6
  deps = ["transformers", "torch", "fastapi", "uvicorn", "huggingface_hub", "accelerate"]
7
 
 
8
  for dep in deps:
9
  try:
10
+ importlib.import_module(dep)
11
  except ImportError:
12
  print(f"Installing missing dependency: {dep}")
13
  subprocess.check_call([sys.executable, "-m", "pip", "install", dep])
14
 
15
+ # Now delay-import your app
16
+ print("Dependencies installed. Loading server...")
17
+ import main # <-- this is now safe to import AFTER accelerate exists