丽水查重代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
4.1KB

  1. # 填充API Key与Secret Key
  2. import requests
  3. import json
  4. import pandas as pd
  5. import re
  6. # 获取百度token验证
  7. def get_access_token():
  8. app_key = "0nbZsMNAWGCU7rLp6olAXVUG"
  9. app_secret = "gWgVIEMpf85npswY0XahUncx6aZGa8e3"
  10. url = f"https://aip.baidubce.com/oauth/2.0/token?client_id={app_key}&client_secret={app_secret}&grant_type=client_credentials"
  11. payload = json.dumps("")
  12. headers = {
  13. 'Content-Type': 'application/json',
  14. 'Accept': 'application/json'
  15. }
  16. response = requests.request("POST", url, headers=headers, data=payload)
  17. return response.json().get("access_token")
  18. # 使用百度文心一言获取文本相识度
  19. def CallResult(prompt):
  20. token = "24.b7829fa01d73e3a4187c73fe7e27316c.2592000.1696475561.282335-38769936"
  21. headers = {
  22. 'Content-Type': 'application/json',
  23. }
  24. data = json.dumps({
  25. 'temperature': 0.1,
  26. 'top_p': 0.8,
  27. "penalty_score": 1.0,
  28. 'messages': [
  29. {
  30. "role": "user", # 提问者角色
  31. "content": prompt # 提问内容
  32. }
  33. ],
  34. })
  35. # print("ChatGLM prompt:",prompt)
  36. # 调用api
  37. response = requests.post(f"https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions?access_token={token}",headers=headers,data=data)
  38. if response.status_code != 200:
  39. return 0, "查询结果错误"
  40. resp = response.json()
  41. print(f"查重结果: {resp['result']}")
  42. pattern = r"\d+\.?\d*"
  43. nums = re.findall(pattern, resp['result'])
  44. if len(nums) > 0:
  45. print("提取到的数字:", nums[0])
  46. n = float(nums[0])
  47. if n is None:
  48. return 0, ""
  49. # resp['result'] = str(resp['result']).replace("\n", " ")
  50. # prompt = prompt.replace("\n", " ")
  51. # with open('train.json', 'a') as file:
  52. # file.write("{" + f""""content": "{prompt}","summary": "{resp['result']}" """ + "}\n")
  53. return n, resp['result']
  54. return 0, ""
  55. # 整理百度返回的格式
  56. def format_data(prompt, result):
  57. with open('train.json', 'w') as file:
  58. file.write(f"")
  59. return
  60. if __name__ == '__main__':
  61. access_token = get_access_token()
  62. print(access_token)
  63. result = CallResult("告诉我下面两段话的重复率百分比是多少:1. 城市总体态势主要从平安指数、生态环保、实有人口、重点人员、重点场所、防灾防控、宏观经济、城市管理、城市监测、事件统计的角度,展示丽水各项城市指标的运行情况。2. 为实现各模块的数据数量、数据接入、历史分析以及部门工作的情况,需要将各模块情况接入分析形成督办驾驶舱。数字化生成:根据市委市政府领导关心的驾驶舱数据生成和展示相关的运行指标,利用数据可视化技术,通过数据驾驶舱方式集中展示,让领导通过一屏,即可清晰掌握驾驶舱数据指标生成相关的实时情况。数字化生成相关的数据指标主要包括接入驾驶舱预警指标、优质指标、专题页面总数、数据指标总数、涉及部门总数、自动化率、涉及接口总数、采用数据直报的指标总数、数据直报完成率、延迟率、整改率、接口故障率、当前接口故障数场景应用相关统计、接入业务系统相关统计、等30余个统计维度指标。数字化督办:根据城市管理指挥中心工作人员针对每日会商工作推进过程中关心的相关指标,利用数据可视化技术,通过数据驾驶舱方式集中展示,通过数字化督办驾驶舱即可清晰掌握每日会商的工作成效和部门工作情况,方便城市管理指挥中心完善和优化每日会商工作。指标主要包括会商需关注指标数、指标批示数、事项批示数、交办情况、督办情况、部门应急预案相关统计、数字化督办相关指标、带班领导会商次数、议题数等不少于10个统计维度指标。")
  64. print("回答结果:", result)
  65. # 使用正则表达式提取小数和整数
  66. # pattern = r"\d+\.?\d*"
  67. # nums = re.findall(pattern, result)
  68. # if len(nums) > 0:
  69. # print("提取到的数字:", nums[0])