Spaces:
Sleeping
Sleeping
pablovela5620
commited on
Commit
•
b49c7d1
1
Parent(s):
03e291a
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
PIXI_PATH = Path("/home/user/.pixi/bin/pixi")
|
5 |
+
PIXI_VERSION = "0.32.1"
|
6 |
+
|
7 |
+
|
8 |
+
def check_and_install_pixi() -> None:
|
9 |
+
try:
|
10 |
+
subprocess.check_call(f"{PIXI_PATH} --version", shell=True)
|
11 |
+
except subprocess.CalledProcessError:
|
12 |
+
print("pixi not found. Installing pixi...")
|
13 |
+
# Install pixi using the provided installation script
|
14 |
+
subprocess.check_call(
|
15 |
+
f"PIXI_VERSION=v{PIXI_VERSION} curl -fsSL https://pixi.sh/install.sh | bash",
|
16 |
+
shell=True,
|
17 |
+
)
|
18 |
+
subprocess.check_call(
|
19 |
+
f"{PIXI_PATH} self-update --version {PIXI_VERSION}", shell=True
|
20 |
+
)
|
21 |
+
subprocess.check_call(f"{PIXI_PATH} --version", shell=True)
|
22 |
+
|
23 |
+
|
24 |
+
def run_command(command: str) -> None:
|
25 |
+
try:
|
26 |
+
subprocess.check_call(command, shell=True)
|
27 |
+
except subprocess.CalledProcessError as e:
|
28 |
+
print(f"run command {command}. Error: {e}")
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
check_and_install_pixi()
|
33 |
+
# install lsof
|
34 |
+
run_command(command=f"{PIXI_PATH} global install lsof")
|
35 |
+
# kill anything running on port 7860
|
36 |
+
run_command(command=f"{PIXI_PATH.parent}/lsof -t -i:7860 | xargs -r kill")
|
37 |
+
# clean current environment
|
38 |
+
run_command(command=f"{PIXI_PATH} clean")
|
39 |
+
# run spaces app
|
40 |
+
run_command(command=f"{PIXI_PATH} run -e spaces app")
|