Spaces:
Sleeping
Sleeping
File size: 2,051 Bytes
97f07be 438a207 97f07be 0c61c42 97f07be 70c5a8b f4ad80e 97f07be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import os
import sys
import subprocess
import importlib.metadata
def config_env():
packages_to_install = [
('gradio',None),
('numpy',None),
('tensorflow', '2.9'),
('keras', '2.9'),
('opencv-python-headless', '4.5.5.64'),
('python-dotenv', None),
('torch', None),
('torchvision', None),
('xplique', None),
('segment_anything', None),
('panopticapi', None),
('keras_cv_attention_models',None)
]
name_to_command = {'segment_anything':'git+https://github.com/facebookresearch/segment-anything.git',
'panopticapi':'git+https://github.com/cocodataset/panopticapi.git',
}
env_name = os.path.basename(sys.prefix)
# print(env_name)
for package, version in packages_to_install:
package_spec = f"{package}=={version}" if version else package
package_spec = name_to_command[package_spec] if package_spec in name_to_command else package_spec
if not is_pkg_installed(package):
subprocess.call(f"pip install {package_spec}".split())
else:
print(f"{package_spec} is already installed.")
#print(os.getenv('SYSTEM'))
'''
if os.getenv('SYSTEM') == 'spaces':
subprocess.call('pip install tensorflow==2.9'.split())
subprocess.call('pip install keras==2.9'.split())
subprocess.call('pip install git+https://github.com/facebookresearch/segment-anything.git'.split())
subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
subprocess.call('pip install git+https://github.com/cocodataset/panopticapi.git'.split())
subprocess.call('pip install python-dotenv'.split())
subprocess.call('pip install torch torchvision '.split())
subprocess.call('pip install xplique'.split())
'''
def is_pkg_installed(pkg_name):
try:
importlib.metadata.distribution(pkg_name)
return True
except importlib.metadata.PackageNotFoundError:
return False
|