File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 3131import queue
3232import threading
3333from typing import Dict , List
34-
34+ import base64
35+ from PIL import Image
36+ from io import BytesIO
3537import numpy as np
3638import torch
3739import triton_python_backend_utils as pb_utils
@@ -397,12 +399,21 @@ async def generate(self, request):
397399 )
398400 if multi_modal_data_input_tensor :
399401 multi_modal_data = multi_modal_data_input_tensor .as_numpy ()[0 ].decode ("utf-8" )
400- # Build TextPrompt format prompt for multi modal models
401402 multi_modal_data = json .loads (multi_modal_data )
402- prompt = {
403- "prompt" : prompt ,
404- "multi_modal_data" : multi_modal_data
405- }
403+ if "image" in multi_modal_data :
404+ image_list = []
405+ for image_base64_string in multi_modal_data ["image" ]:
406+ if "base64," in image_base64_string :
407+ image_base64_string = image_base64_string .split ("base64," )[- 1 ]
408+ image_data = base64 .b64decode (image_base64_string )
409+ image = Image .open (BytesIO (image_data )).convert ("RGB" )
410+ image_list .append (image )
411+ prompt = {
412+ "prompt" : prompt ,
413+ "multi_modal_data" : {
414+ "image" : image_list
415+ }
416+ }
406417
407418 stream = pb_utils .get_input_tensor_by_name (request , "stream" )
408419 if stream :
You can’t perform that action at this time.
0 commit comments