flaskBack.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from flask import Flask, request
  2. from interface import annotate
  3. from flask_cors import CORS
  4. from flask import jsonify
  5. from utils.fileio import load_json
  6. app = Flask("PrivacyScan")
  7. cors = CORS(app, resources={r"/scan": {"origins": "*"}})
  8. @app.route("/scan", methods=['POST'])
  9. def scan():
  10. source = request.get_json()['source']
  11. print(request.get_json())
  12. data_type = load_json('lattices/datatype_dictionary.json')
  13. purpose_dict = load_json('lattices/purpose_dictionary.json')
  14. lattice = {'dataType': data_type, 'purpose': purpose_dict}
  15. result = annotate(source, lattice,
  16. False)
  17. # result = {
  18. # 'accuracy': {
  19. # 'recall_accurate': 10,
  20. # 'recall_location': 128,
  21. # 'location_num': 158
  22. # },
  23. # 'missed': {
  24. # 'suspected_node_list': ["第一个文件 第一行", "第一个文件 第二行"],
  25. # 'missed': ["命中:第一个文件 第一行", "未命中:第二个文件第三行"]
  26. # }
  27. # }
  28. print(source)
  29. return jsonify(result)
  30. if __name__ == '__main__':
  31. app.run()