Spaces:
Paused
Paused
yeser
Browse files
app.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
import subprocess
|
2 |
import sys
|
|
|
3 |
|
4 |
-
# List of dependencies
|
5 |
deps = ["transformers", "torch", "fastapi", "uvicorn", "huggingface_hub", "accelerate"]
|
6 |
|
7 |
-
# Attempt to install anything missing
|
8 |
for dep in deps:
|
9 |
try:
|
10 |
-
|
11 |
except ImportError:
|
12 |
print(f"Installing missing dependency: {dep}")
|
13 |
subprocess.check_call([sys.executable, "-m", "pip", "install", dep])
|
14 |
|
15 |
-
# Now import
|
16 |
-
|
|
|
|
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
|