image.py (2740B)
1 import modal 2 3 omniparser_v2_0_1 = ( 4 modal.Image.debian_slim(python_version="3.12") 5 .apt_install(["wget", "curl", "libgl1", "libglib2.0-0"]) 6 .shell(["/bin/bash", "-c"]) 7 .env({"CONDA_DIR": "/opt/conda"}) 8 .run_commands( 9 [ 10 "mkdir -p $CONDA_DIR", 11 "wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $CONDA_DIR/miniconda.sh", 12 "bash $CONDA_DIR/miniconda.sh -b -u -p $CONDA_DIR", 13 "rm $CONDA_DIR/miniconda.sh", 14 "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main", 15 "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r", 16 "$CONDA_DIR/bin/conda init --all", 17 ] 18 ) 19 .run_commands( 20 [ 21 "wget https://github.com/microsoft/OmniParser/archive/refs/tags/v.2.0.1.tar.gz -O OmniParser.tar.gz", 22 "tar -xzf OmniParser.tar.gz", 23 "mv OmniParser-* OmniParser", 24 ] 25 ) 26 .workdir("OmniParser") 27 .add_local_file( 28 "omniparser-requirements.txt", "/etc/omniparser-requirements.txt", copy=True 29 ) 30 .run_commands( 31 [ 32 "cp /etc/omniparser-requirements.txt requirements.txt", 33 "$CONDA_DIR/bin/conda create -n omni python==3.12 -y", 34 "$CONDA_DIR/bin/conda run -n omni pip install -r requirements.txt", 35 "$CONDA_DIR/bin/conda install -n omni cuda -c nvidia/label/cuda-12.2.0 -y", 36 ] 37 ) 38 .env( 39 {"PATH": "$CONDA_DIR/envs/omni/bin:$PATH", "CUDA_HOME": "$CONDA_DIR/envs/omni"} 40 ) 41 .run_commands( 42 [ 43 "wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.6.0/flash_attn-2.6.0+cu122torch2.2cxx11abiFALSE-cp312-cp312-linux_x86_64.whl", 44 "$CONDA_DIR/bin/conda run -n omni pip install --no-dependencies flash_attn-2.6.0+cu122torch2.2cxx11abiFALSE-cp312-cp312-linux_x86_64.whl", 45 ] 46 ) 47 .run_commands("curl -LsSf https://hf.co/cli/install.sh | bash") 48 .run_commands( 49 [ 50 "; ".join( 51 [ 52 "for f in icon_detect/{train_args.yaml,model.pt,model.yaml} icon_caption/{config.json,generation_config.json,model.safetensors}", 53 'do env PATH="/root/.local/bin:$PATH" hf download microsoft/OmniParser-v2.0 "$f" --local-dir weights', 54 "done", 55 ] 56 ), 57 "mv weights/icon_caption weights/icon_caption_florence", 58 ] 59 ) 60 .env({"TOKENIZERS_PARALLELISM": "false"}) 61 .add_local_python_source("volume") 62 .add_local_python_source("image") 63 .add_local_python_source("parse") 64 .add_local_python_source("app") 65 )