Spaces:
Sleeping
Sleeping
pablovela5620
commited on
Commit
•
e37e4d1
1
Parent(s):
cbfea5f
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
PIXI_PATH = Path("/home/user/.pixi/bin/pixi")
|
5 |
+
BREW_PATH = Path("/home/linuxbrew/.linuxbrew/bin/brew")
|
6 |
+
LSOF_PATH = Path("/home/linuxbrew/.linuxbrew/Cellar/lsof/4.99.3/bin/lsof")
|
7 |
+
|
8 |
+
|
9 |
+
def check_and_install_pixi() -> None:
|
10 |
+
try:
|
11 |
+
subprocess.check_call(f"{PIXI_PATH} --version", shell=True)
|
12 |
+
except subprocess.CalledProcessError:
|
13 |
+
print("pixi not found. Installing pixi...")
|
14 |
+
# Install pixi using the provided installation script
|
15 |
+
subprocess.check_call(
|
16 |
+
"curl -fsSL https://pixi.sh/install.sh | bash", shell=True
|
17 |
+
)
|
18 |
+
|
19 |
+
|
20 |
+
def check_and_install_homebrew() -> None:
|
21 |
+
try:
|
22 |
+
# Check if Homebrew is installed
|
23 |
+
subprocess.check_call(f"{BREW_PATH} --version", shell=True)
|
24 |
+
except subprocess.CalledProcessError:
|
25 |
+
# If Homebrew is not found, install it
|
26 |
+
print("Homebrew not found. Installing Homebrew...")
|
27 |
+
subprocess.check_call(
|
28 |
+
'/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
|
29 |
+
shell=True,
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
def install_package(package_name) -> None:
|
34 |
+
try:
|
35 |
+
# Install the specified package using Homebrew
|
36 |
+
subprocess.check_call(f"{BREW_PATH} install {package_name}", shell=True)
|
37 |
+
print(f"{package_name} installed successfully.")
|
38 |
+
except subprocess.CalledProcessError as e:
|
39 |
+
print(f"Failed to install {package_name}. Error: {e}")
|
40 |
+
|
41 |
+
|
42 |
+
def run_command(command: str) -> None:
|
43 |
+
try:
|
44 |
+
subprocess.check_call(command, shell=True)
|
45 |
+
except subprocess.CalledProcessError as e:
|
46 |
+
print(f"run command {command}. Error: {e}")
|
47 |
+
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
check_and_install_homebrew()
|
51 |
+
install_package(package_name="lsof")
|
52 |
+
check_and_install_pixi()
|
53 |
+
run_command(command=f"{LSOF_PATH} -t -i:7860 | xargs -r kill")
|
54 |
+
run_command(command=f"{PIXI_PATH} run -e spaces app")
|