modal-omniparser

A serverless compute port of the OmniParser vision model for the Modal platform.
git clone https://unitehenry.com/git/modal-omniparser.git
Log | Files | Refs | README

commit 0b09f89917a90c5554f5d401eab86caa89934c9d
parent 55575df6196a4e9cd224b125d872061fd06df5e9
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 14 Mar 2026 18:52:46 +0000

refactor: image module

Diffstat:
Mapp.py | 64++--------------------------------------------------------------
Aimage.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 62 deletions(-)

diff --git a/app.py b/app.py @@ -1,70 +1,10 @@ -import functools import modal import volume +import image app = modal.App("omniparser") -image = ( - modal.Image.debian_slim(python_version="3.12") - .apt_install(["wget", "curl", "libgl1", "libglib2.0-0"]) - .shell(["/bin/bash", "-c"]) - .env({"CONDA_DIR": "/opt/conda"}) - .run_commands( - [ - "mkdir -p $CONDA_DIR", - "wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $CONDA_DIR/miniconda.sh", - "bash $CONDA_DIR/miniconda.sh -b -u -p $CONDA_DIR", - "rm $CONDA_DIR/miniconda.sh", - "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main", - "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r", - "$CONDA_DIR/bin/conda init --all", - ] - ) - .run_commands( - [ - "wget https://github.com/microsoft/OmniParser/archive/refs/tags/v.2.0.1.tar.gz -O OmniParser.tar.gz", - "tar -xzf OmniParser.tar.gz", - "mv OmniParser-* OmniParser", - ] - ) - .workdir("OmniParser") - .run_commands( - [ - "sed -i 's/\<paddleocr\>/paddleocr<=2.8/g' requirements.txt", - "sed -i 's/\<torch\>/torch==2.2.0/g' requirements.txt", - "sed -i 's/\<transformers\>/transformers==4.38.2/g' requirements.txt", - "sed -i 's/\<paddlepaddle\>/paddlepaddle<=2.8/g' requirements.txt", - "$CONDA_DIR/bin/conda create -n omni python==3.12 -y", - "$CONDA_DIR/bin/conda run -n omni pip install -r requirements.txt", - "$CONDA_DIR/bin/conda install -n omni cuda -c nvidia/label/cuda-12.2.0 -y", - ] - ) - .env( - {"PATH": "$CONDA_DIR/envs/omni/bin:$PATH", "CUDA_HOME": "$CONDA_DIR/envs/omni"} - ) - .run_commands( - [ - "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", - "$CONDA_DIR/bin/conda run -n omni pip install --no-dependencies flash_attn-2.6.0+cu122torch2.2cxx11abiFALSE-cp312-cp312-linux_x86_64.whl", - ] - ) - .run_commands("curl -LsSf https://hf.co/cli/install.sh | bash") - .run_commands( - [ - "; ".join( - [ - "for f in icon_detect/{train_args.yaml,model.pt,model.yaml} icon_caption/{config.json,generation_config.json,model.safetensors}", - 'do env PATH="/root/.local/bin:$PATH" hf download microsoft/OmniParser-v2.0 "$f" --local-dir weights', - "done", - ] - ), - "mv weights/icon_caption weights/icon_caption_florence", - ]) - .add_local_python_source("volume") -) - - -@app.function(gpu="h100", image=image, volumes={"/data": volume.vol}) +@app.function(gpu="h100", image=image.omniparser_v2_0_1, volumes={"/data": volume.vol}) @volume.cache def parse(): import time diff --git a/image.py b/image.py @@ -0,0 +1,61 @@ +import modal + +omniparser_v2_0_1 = ( + modal.Image.debian_slim(python_version="3.12") + .apt_install(["wget", "curl", "libgl1", "libglib2.0-0"]) + .shell(["/bin/bash", "-c"]) + .env({"CONDA_DIR": "/opt/conda"}) + .run_commands( + [ + "mkdir -p $CONDA_DIR", + "wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $CONDA_DIR/miniconda.sh", + "bash $CONDA_DIR/miniconda.sh -b -u -p $CONDA_DIR", + "rm $CONDA_DIR/miniconda.sh", + "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main", + "$CONDA_DIR/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r", + "$CONDA_DIR/bin/conda init --all", + ] + ) + .run_commands( + [ + "wget https://github.com/microsoft/OmniParser/archive/refs/tags/v.2.0.1.tar.gz -O OmniParser.tar.gz", + "tar -xzf OmniParser.tar.gz", + "mv OmniParser-* OmniParser", + ] + ) + .workdir("OmniParser") + .run_commands( + [ + "sed -i 's/\<paddleocr\>/paddleocr<=2.8/g' requirements.txt", + "sed -i 's/\<torch\>/torch==2.2.0/g' requirements.txt", + "sed -i 's/\<transformers\>/transformers==4.38.2/g' requirements.txt", + "sed -i 's/\<paddlepaddle\>/paddlepaddle<=2.8/g' requirements.txt", + "$CONDA_DIR/bin/conda create -n omni python==3.12 -y", + "$CONDA_DIR/bin/conda run -n omni pip install -r requirements.txt", + "$CONDA_DIR/bin/conda install -n omni cuda -c nvidia/label/cuda-12.2.0 -y", + ] + ) + .env( + {"PATH": "$CONDA_DIR/envs/omni/bin:$PATH", "CUDA_HOME": "$CONDA_DIR/envs/omni"} + ) + .run_commands( + [ + "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", + "$CONDA_DIR/bin/conda run -n omni pip install --no-dependencies flash_attn-2.6.0+cu122torch2.2cxx11abiFALSE-cp312-cp312-linux_x86_64.whl", + ] + ) + .run_commands("curl -LsSf https://hf.co/cli/install.sh | bash") + .run_commands( + [ + "; ".join( + [ + "for f in icon_detect/{train_args.yaml,model.pt,model.yaml} icon_caption/{config.json,generation_config.json,model.safetensors}", + 'do env PATH="/root/.local/bin:$PATH" hf download microsoft/OmniParser-v2.0 "$f" --local-dir weights', + "done", + ] + ), + "mv weights/icon_caption weights/icon_caption_florence", + ]) + .add_local_python_source("volume") + .add_local_python_source("image") +)