Skip to content

Commit

Permalink
update v0.2.5
Browse files Browse the repository at this point in the history
- 修复了一些问题
  • Loading branch information
Zeyi-Lin committed Jul 12, 2023
1 parent 2f32ed5 commit eea7e9a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion predict.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from swanapi import SwanInference
import cv2


# 这是一个简单的图像转黑白的任务
def predict(im):
result_image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
return "success", result_image


if __name__ == "__main__":
api = SwanInference()
api.inference(predict,
inputs=['image'],
outputs=['text', 'image'],
description="a simple test")
api.launch()
api.launch()
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='swanapi',
version='0.2.4',
version='0.2.5',
author='ZeYiLin',
author_email='zeyi.lin@swanhub.co',
description='A low threshold, high performance, compatible with a variety of different scenarios of'
Expand Down
12 changes: 8 additions & 4 deletions swanapi/base_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self.requests_inputs = None
self.requests_inputs_param_names = None
self.requests_outputs_variables_num = None
self.description = None

def backbone_type_checker(self) -> None:
# 如果fn是列表,报错
Expand Down Expand Up @@ -94,7 +95,8 @@ def requests_input_type_checker(self, requests_inputs: Dict[str, Any]) -> None:
# 判断网络请求输入的参数的个数是否与inputs定义的个数一致
assert len(self.requests_inputs_param_names) == len(self.backbone_inputs), "请求传入的参数数量与inputs定义的不一致"
# 判断网络请求输入的参数名是否与fn定义的一致
assert utils.check_elements_in_list(self.requests_inputs_param_names, self.fn_param_names), "请求传入的参数key与fn定义的不一致"
assert utils.check_elements_in_list(self.requests_inputs_param_names,
self.fn_param_names), "请求传入的参数key与fn定义的不一致"

def requests_input_converter(self) -> None:
# 对于每一个requests内容的输入类型,做相应的转换
Expand Down Expand Up @@ -177,15 +179,17 @@ def requests_output_converter(self, result: Any) -> Union[Dict[str, Any], None]:
assert isinstance(result[iter], (int, float))
result_json[iter] = {"content": result[iter]}

elif backbone_output == ["dict"]:
elif backbone_output == "dict":
assert isinstance(result, dict)
result_json[iter] = {"content": result[iter]}

elif backbone_output == ["list"]:
elif backbone_output == "list":
assert isinstance(result, list)
result_json[iter] = {"content": result[iter]}

else:
raise TypeError("类型检查模块存在Bug")

return result_json

def get_description(self):
return self.description
5 changes: 5 additions & 0 deletions swanapi/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,10 @@ def encode_url_or_file_to_base64(path: Union[str, Path]):


def bytes_to_array(bytes_data):
"""
将字节流解码成PIL风格的numpy
:param bytes_data:
:return:
"""
im = _Image.open(BytesIO(bytes_data))
return np.array(im)

0 comments on commit eea7e9a

Please sign in to comment.