client.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import requests, os
  2. from config import *
  3. def cls_process_openai(path, client_id, one_key, name_column, api_key="sk-iREtaVNjamaBArOTlc_2BfGFJVPiU-9EjSFMUspIPBT3BlbkFJxS0SMmKZD9L9UumPczee4VKawCwVeGBQAr9MgsWGkA",
  4. proxy=False, chunk_size=100):
  5. # 定义请求的数据
  6. data = {
  7. "path": path,
  8. "client_id": client_id,
  9. "one_key": one_key,
  10. "name_column": name_column,
  11. "api_key": api_key,
  12. "proxy": proxy,
  13. "chunk_size":chunk_size
  14. }
  15. # 发送 POST 请求
  16. response = requests.post(f"http://{ip}:8070/classify_openai/", json=data)
  17. # 处理响应
  18. if response.status_code == 200:
  19. result = response.json()
  20. print("接口响应:", result)
  21. else:
  22. print(f"请求失败,状态码: {response.status_code}")
  23. print("错误信息:", response.text)
  24. def cls_process_bert(path, client_id, name_column):
  25. # 定义请求的数据
  26. data = {
  27. "path": path,
  28. "client_id": client_id,
  29. "name_column": name_column
  30. }
  31. # 发送 POST 请求
  32. response = requests.post(f"http://{ip}:8070/classify_bert/", json=data)
  33. # 处理响应
  34. if response.status_code == 200:
  35. result = response.json()
  36. print("接口响应:", result)
  37. else:
  38. print(f"请求失败,状态码: {response.status_code}")
  39. print("错误信息:", response.text)
  40. def upload_process(file_path, client_id):
  41. # 表单数据
  42. data = {
  43. 'client_id': client_id
  44. }
  45. # 发送 POST 请求
  46. with open(file_path, 'rb') as file:
  47. name = os.path.basename(file_path)
  48. files = {
  49. 'file': (name, file, 'text/plain') # 'text/plain' 是文件类型,可以根据需要修改
  50. }
  51. response = requests.post(f"http://{ip}:8070/uploadfile/", data=data, files=files)
  52. # 处理响应
  53. if response.status_code == 200:
  54. result = response.json()
  55. print("接口响应:", result)
  56. return result.get('file_path')
  57. else:
  58. print(f"请求失败,状态码: {response.status_code}")
  59. print("错误信息:", response.text)
  60. return None
  61. def both_process_api(path, client_id, one_key, name_column):
  62. file_path = upload_process(file_path=path, client_id=client_id)
  63. if file_path:
  64. cls_process_openai(path=file_path, client_id=client_id, one_key=one_key, name_column=name_column)
  65. def both_process_bert(path, client_id, name_column):
  66. file_path = upload_process(file_path=path, client_id=client_id)
  67. if file_path:
  68. cls_process_bert(path=file_path, client_id=client_id, name_column=name_column)
  69. if __name__ == "__main__":
  70. # both_process(path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin', one_key='网店单号', name_column='收货姓名')
  71. # upload_process(file_path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin')
  72. # cls_process_openai(path="./process/wangdalin\\人群分类-自建站2024.08.xlsx",client_id='wangdalin', one_key='网店单号', name_column='收货姓名')
  73. # cls_process_bert(path="./process/wangdalin/人群分类-自建站2024.08.xlsx",client_id='wangdalin', name_column='收货姓名')
  74. both_process_bert(path='/dalin/name_classify/process/1售后Shopify退货人群匹配0902-0908.xlsx', client_id='wangdalin', name_column='姓名')
  75. # cls_process_bert(path='/mnt/e/code/name_classify/process/wangdalin/3销售Shopify人群分析0902-0908_classify_error.xlsx', client_id='wangdalin', name_column='姓名')