You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
psy/api_send_inference.py

98 lines
3.1 KiB
Python

from pydantic import BaseModel
if __name__ == "__main__":
import requests
# 模拟发送的特征数据
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_data3]
features_data_list = [features_data4, features_data2, features_data3, features_data1]
# 发送 POST 请求
response = requests.post("http://127.0.0.1:3397/inference/", json=features_data_list)
if response.status_code == 200:
# 获取分类结果列表
classified_results = response.json()
print(classified_results) # 这里的 classified_results 就是返回的列表对象
else:
print("请求失败:", response.text)