commit fc69c0b7cc948efad3d5bfdb9e510512aada8b55
parent 6a8bacd47c67c89fcb8187057eeaea1fc213d316
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 15 Mar 2026 00:27:32 +0000
feat: save omniparser labeled output
Diffstat:
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/parse.py b/parse.py
@@ -14,6 +14,9 @@ def parse(file_url: str):
import urllib.request
import tempfile
import os
+ import io
+ import base64
+ import subprocess
from util.utils import (
get_som_labeled_img,
check_ocr_box,
@@ -92,4 +95,13 @@ def parse(file_url: str):
cur_time_caption = time.time()
+ labeled_image = Image.open(io.BytesIO(base64.b64decode(dino_labled_img)))
+
+ os.makedirs("/root/output", exist_ok=True)
+
+ with open("/root/output/output.png", "wb") as output_file:
+ labeled_image.save(output_file.name)
+
+ volume.save_dir("/root/output")
+
return json.dumps(parsed_content_list)
diff --git a/volume.py b/volume.py
@@ -3,6 +3,19 @@ from functools import wraps
vol = modal.Volume.from_name("omniparser", create_if_missing=True)
+def save_dir(dir_name : str):
+ import os
+ import subprocess
+
+ print(dir_name)
+
+ print(["mv", "-f", "--", dir_name, f"/data/output"])
+
+ print(subprocess.run(
+ ["mv", "-f", "--", dir_name, f"/data/output"], check=False, capture_output=True, text=True
+ ))
+
+ vol.commit()
def cache(func):
import os
@@ -25,6 +38,7 @@ def cache(func):
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
)