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 55575df6196a4e9cd224b125d872061fd06df5e9
parent 879af65dd10950f80598fda73f0b7670a3dece60
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 14 Mar 2026 18:47:27 +0000

refactor: volume module

Diffstat:
Mapp.py | 39+++++----------------------------------
Avolume.py | 31+++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/app.py b/app.py @@ -1,9 +1,8 @@ import functools import modal -from functools import wraps +import volume app = modal.App("omniparser") -vol = modal.Volume.from_name("omniparser", create_if_missing=True) image = ( modal.Image.debian_slim(python_version="3.12") @@ -60,41 +59,13 @@ image = ( ] ), "mv weights/icon_caption weights/icon_caption_florence", - ] - ) + ]) + .add_local_python_source("volume") ) -def cache(func): - import os - import subprocess - - CACHE_PATHS = [ - ".paddleocr", - ".EasyOCR", - ".config/Ultralytics", - ".cache/huggingface/hub", - ] - - @wraps(func) - def wrapper(*args, **kwargs): - for path in CACHE_PATHS: - subprocess.run(["mv", "-f", "--", f"/data/{path}", "/root"], check=False) - - try: - return func(*args, **kwargs) - finally: - for path in CACHE_PATHS: - os.makedirs(os.path.dirname(f"/data/{path}"), exist_ok=True) - subprocess.run( - ["mv", "-f", "--", f"/root/{path}", f"/data/{path}"], check=False - ) - - return wrapper - - -@app.function(gpu="h100", image=image, volumes={"/data": vol}) -@cache +@app.function(gpu="h100", image=image, volumes={"/data": volume.vol}) +@volume.cache def parse(): import time import importlib diff --git a/volume.py b/volume.py @@ -0,0 +1,31 @@ +import modal +from functools import wraps + +vol = modal.Volume.from_name("omniparser", create_if_missing=True) + +def cache(func): + import os + import subprocess + + CACHE_PATHS = [ + ".paddleocr", + ".EasyOCR", + ".config/Ultralytics", + ".cache/huggingface/hub", + ] + + @wraps(func) + def wrapper(*args, **kwargs): + for path in CACHE_PATHS: + subprocess.run(["mv", "-f", "--", f"/data/{path}", "/root"], check=False) + + try: + return func(*args, **kwargs) + finally: + for path in CACHE_PATHS: + os.makedirs(os.path.dirname(f"/data/{path}"), exist_ok=True) + subprocess.run( + ["mv", "-f", "--", f"/root/{path}", f"/data/{path}"], check=False + ) + + return wrapper