import requests, os def cls_process_openai(path, client_id, one_key, name_column, api_key="sk-iREtaVNjamaBArOTlc_2BfGFJVPiU-9EjSFMUspIPBT3BlbkFJxS0SMmKZD9L9UumPczee4VKawCwVeGBQAr9MgsWGkA", proxy=False, chunk_size=100): # 定义请求的数据 data = { "path": path, "client_id": client_id, "one_key": one_key, "name_column": name_column, "api_key": api_key, "proxy": proxy, "chunk_size":chunk_size } # 发送 POST 请求 response = requests.post("http://172.28.5.44:8070/classify_openai/", json=data) # 处理响应 if response.status_code == 200: result = response.json() print("接口响应:", result) else: print(f"请求失败,状态码: {response.status_code}") print("错误信息:", response.text) def cls_process_bert(path, client_id, name_column): # 定义请求的数据 data = { "path": path, "client_id": client_id, "name_column": name_column } # 发送 POST 请求 response = requests.post("http://172.28.5.44:8070/classify_bert/", json=data) # 处理响应 if response.status_code == 200: result = response.json() print("接口响应:", result) else: print(f"请求失败,状态码: {response.status_code}") print("错误信息:", response.text) def upload_process(file_path, client_id): # 表单数据 data = { 'client_id': client_id } # 发送 POST 请求 with open(file_path, 'rb') as file: name = os.path.basename(file_path) files = { 'file': (name, file, 'text/plain') # 'text/plain' 是文件类型,可以根据需要修改 } response = requests.post("http://ip:port/uploadfile/", data=data, files=files) # 处理响应 if response.status_code == 200: result = response.json() print("接口响应:", result) return result.get('file_path') else: print(f"请求失败,状态码: {response.status_code}") print("错误信息:", response.text) return None def both_process(path, client_id, one_key, name_column): file_path = upload_process(file_path=path, client_id=client_id) if file_path: cls_process_openai(path=file_path, client_id=client_id, one_key=one_key, name_column=name_column) if __name__ == "__main__": # both_process(path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin', one_key='网店单号', name_column='收货姓名') # upload_process(file_path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin') # cls_process_openai(path="./process/wangdalin\\人群分类-自建站2024.08.xlsx",client_id='wangdalin', one_key='网店单号', name_column='收货姓名') cls_process_bert(path="./process/wangdalin/人群分类-自建站2024.08.xlsx",client_id='wangdalin', name_column='收货姓名')