pyinstaller inference test
parent
6fb87495d7
commit
ec18b2342c
@ -0,0 +1,108 @@
|
||||
from pydantic import BaseModel
|
||||
import requests
|
||||
import argparse
|
||||
|
||||
def main(server: str, port: int):
|
||||
# 模拟发送的特征数据
|
||||
features_data1 = {
|
||||
"somatization": 0.5,
|
||||
"obsessive_compulsive": 0.3,
|
||||
"interpersonal_sensitivity": 0.7,
|
||||
"depression": 0.6,
|
||||
"anxiety": 0.8,
|
||||
"hostility": 0.4,
|
||||
"terror": 0.2,
|
||||
"paranoia": 0.1,
|
||||
"psychoticism": 0.9,
|
||||
"other": 0.2,
|
||||
"father_parenting_style": 2,
|
||||
"mother_parenting_style": 3,
|
||||
"self_assessed_family_economic_condition": 4,
|
||||
"history_of_psychological_counseling": 1,
|
||||
"absenteeism_above_average": True,
|
||||
"academic_warning": False,
|
||||
"label": -1
|
||||
}
|
||||
features_data2 = {
|
||||
"somatization": 4.3,
|
||||
"obsessive_compulsive": 4.1,
|
||||
"interpersonal_sensitivity": 3.8,
|
||||
"depression": 4,
|
||||
"anxiety": 4.2,
|
||||
"hostility": 4.2,
|
||||
"terror": 4,
|
||||
"paranoia": 4.2,
|
||||
"psychoticism": 3.8,
|
||||
"other": 3.6,
|
||||
"father_parenting_style": 1,
|
||||
"mother_parenting_style": 0,
|
||||
"self_assessed_family_economic_condition": 0,
|
||||
"history_of_psychological_counseling": False,
|
||||
"absenteeism_above_average": True,
|
||||
"academic_warning": True,
|
||||
"label": -1
|
||||
}
|
||||
features_data3 = {
|
||||
"somatization": 1.1,
|
||||
"obsessive_compulsive": 2.3,
|
||||
"interpersonal_sensitivity": 2.6,
|
||||
"depression": 2.2,
|
||||
"anxiety": 1.6,
|
||||
"hostility": 1.5,
|
||||
"terror": 1.6,
|
||||
"paranoia": 1.5,
|
||||
"psychoticism": 1.2,
|
||||
"other": 1.3,
|
||||
"father_parenting_style": 1,
|
||||
"mother_parenting_style": 1,
|
||||
"self_assessed_family_economic_condition": 1,
|
||||
"history_of_psychological_counseling": False,
|
||||
"absenteeism_above_average": False,
|
||||
"academic_warning": False,
|
||||
"label": -1
|
||||
}
|
||||
features_data4 = {
|
||||
"somatization": 1.5,
|
||||
"obsessive_compulsive": 2.4,
|
||||
"interpersonal_sensitivity": 2.2,
|
||||
"depression": 3.2,
|
||||
"anxiety": 1.6,
|
||||
"hostility": 1.5,
|
||||
"terror": 3.1,
|
||||
"paranoia": 1.5,
|
||||
"psychoticism": 1.9,
|
||||
"other": 2.6,
|
||||
"father_parenting_style": 1,
|
||||
"mother_parenting_style": 1,
|
||||
"self_assessed_family_economic_condition": 0,
|
||||
"history_of_psychological_counseling": False,
|
||||
"absenteeism_above_average": False,
|
||||
"academic_warning": False,
|
||||
"label": -1
|
||||
}
|
||||
|
||||
# 必须是 features_list, 前面出现了只有一个样本时测不准,考虑是用了样本间归一化的原因,现在么有用了
|
||||
features_data_list = [features_data4, features_data2, features_data3, features_data1]
|
||||
|
||||
# 构建请求 URL
|
||||
url = f"http://{server}:{port}/inference/"
|
||||
|
||||
# 发送 POST 请求
|
||||
response = requests.post(url, json=features_data_list)
|
||||
|
||||
if response.status_code == 200:
|
||||
# 获取分类结果列表
|
||||
classified_results = response.json()
|
||||
print(classified_results) # 这里的 classified_results 就是返回的列表对象
|
||||
else:
|
||||
print("请求失败:", response.text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="发送特征数据到服务器进行推断")
|
||||
parser.add_argument("--server", type=str, default="127.0.0.1", help="服务器地址")
|
||||
parser.add_argument("--port", type=int, default=8088, help="服务器端口")
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args.server, args.port)
|
||||
input("任意键结束!")
|
||||
|
||||
Loading…
Reference in New Issue