taesiri commited on
Commit
fdea97c
·
verified ·
1 Parent(s): cca3ecd

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +31 -15
model.py CHANGED
@@ -7,22 +7,38 @@ import subprocess
7
  import sys
8
  import json
9
 
10
- if os.getenv("SYSTEM") == "spaces":
11
- # Update pip first
12
- subprocess.run(shlex.split("pip install --upgrade pip"), check=True)
13
-
14
- # Install specific versions of mim and click
15
- subprocess.run(shlex.split("pip install mim==0.1.0"), check=True)
16
- subprocess.run(shlex.split("pip install click==8.0.4"), check=True)
17
-
18
- import mim
19
 
20
- mim.uninstall("mmcv-full", confirm_yes=True)
21
- mim.install("mmcv-full==1.5.0", is_yes=True)
22
-
23
- subprocess.run(shlex.split("pip uninstall -y opencv-python"))
24
- subprocess.run(shlex.split("pip uninstall -y opencv-python-headless"))
25
- subprocess.run(shlex.split("pip install opencv-python-headless==4.5.5.64"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  import huggingface_hub
28
  import numpy as np
 
7
  import sys
8
  import json
9
 
10
+ def run_command(command):
11
+ try:
12
+ subprocess.run(shlex.split(command), check=True, capture_output=True, text=True)
13
+ except subprocess.CalledProcessError as e:
14
+ print(f"Error running command '{command}':")
15
+ print(f"Exit code: {e.returncode}")
16
+ print(f"stdout: {e.stdout}")
17
+ print(f"stderr: {e.stderr}")
18
+ raise
19
 
20
+ if os.getenv("SYSTEM") == "spaces":
21
+ try:
22
+ # Update pip first
23
+ run_command("pip install --upgrade pip")
24
+
25
+ # Install openmim version 0.3.9
26
+ run_command("pip install openmim==0.3.9")
27
+
28
+ # Install specific version of click
29
+ run_command("pip install click==8.0.4")
30
+
31
+ from mmcv.utils import install_module, uninstall_module
32
+
33
+ uninstall_module("mmcv-full")
34
+ install_module("mmcv-full==1.5.0")
35
+
36
+ run_command("pip uninstall -y opencv-python")
37
+ run_command("pip uninstall -y opencv-python-headless")
38
+ run_command("pip install opencv-python-headless==4.5.5.64")
39
+ except Exception as e:
40
+ print(f"An error occurred during setup: {str(e)}")
41
+ sys.exit(1)
42
 
43
  import huggingface_hub
44
  import numpy as np