From 11703d957d1e705de972b67e6d37714b2c4d685a Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Fri, 6 Feb 2026 09:50:53 +0800 Subject: [PATCH] Refactor: Improve Picture.py resource usage (#13011) ### What problem does this PR solve? Improve Picture.py resource usage ### Type of change - [x] Refactoring --- rag/app/picture.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rag/app/picture.py b/rag/app/picture.py index d8332fd76..2ad773a3c 100644 --- a/rag/app/picture.py +++ b/rag/app/picture.py @@ -78,10 +78,10 @@ def chunk(filename, binary, tenant_id, lang, callback=None, **kwargs): try: callback(0.4, "Use CV LLM to describe the picture.") cv_mdl = LLMBundle(tenant_id, LLMType.IMAGE2TEXT, lang=lang) - img_binary = io.BytesIO() - img.save(img_binary, format="JPEG") - img_binary.seek(0) - ans = cv_mdl.describe(img_binary.read()) + with io.BytesIO() as img_binary: + img.save(img_binary, format="JPEG") + img_binary.seek(0) + ans = cv_mdl.describe(img_binary.read()) callback(0.8, "CV LLM respond: %s ..." % ans[:32]) txt += "\n" + ans tokenize(doc, txt, eng)