MCPcopy Index your code
hub / github.com/modelscope/modelscope / service_data_decoder

Function service_data_decoder

modelscope/utils/service_utils.py:141–167  ·  view source on GitHub ↗
(task, data)

Source from the content-addressed store, hash-verified

139
140
141def service_data_decoder(task, data):
142 if CustomDecoder.get(task) is not None:
143 return CustomDecoder[task](data)
144 input_data = data.decode('utf-8')
145 input_type = TASK_INPUTS[task]
146 if isinstance(input_type, list):
147 input_type = input_type[0]
148 if input_type == InputType.IMAGE:
149 return decode_base64_to_image(input_data)
150 elif input_type == InputType.AUDIO:
151 return decode_base64_to_binary(input_data)[0]
152 elif input_type == InputType.TEXT:
153 return input_data
154 elif isinstance(input_type, dict):
155 input_data = {}
156 data = json.loads(data)
157 for key, val in input_type.items():
158 if val == InputType.IMAGE:
159 input_data[key] = decode_base64_to_image(data[key])
160 elif val == InputType.AUDIO:
161 input_data[key] = decode_base64_to_binary(data[key])[0]
162 elif val == InputType.TEXT:
163 input_data[key] = data[key]
164 else:
165 return data
166
167 return input_data
168
169
170def service_data_encoder(task, data):

Callers

nothing calls this directly

Calls 5

decode_base64_to_binaryFunction · 0.85
decode_base64_to_imageFunction · 0.70
getMethod · 0.45
decodeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…