app.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from flask import Flask, request
  2. from tool import runtool
  3. import yaml
  4. import os
  5. app = Flask(__name__)
  6. with open('config.yml', 'r') as file:
  7. config = yaml.load(file, Loader=yaml.FullLoader)
  8. env = os.getenv('FLASK_ENV', 'development')
  9. app.config.update(config['default'])
  10. if env in config:
  11. app.config.update(config[env])
  12. @app.route('/')
  13. def hello_world(): # put application's code here
  14. return 'Hello World!'
  15. @app.route('/models', methods=['GET'])
  16. def getModels():
  17. models = ['lexnet-cifar10', 'lenet5-fashion-mnist', 'fashion2', 'svhn', 'lenet5-mnist',
  18. 'alexnet-cifar10', 'mobilenet.1.00.224-imagenet', 'vgg16-imagenet']
  19. return models
  20. @app.route('/run', methods=['POST'])
  21. def run():
  22. data = request.get_json()
  23. exp = data['exp']
  24. mutate_num = data['mutate_num']
  25. root_dir = app.config['root_dir']
  26. output_dir = app.config['output_dir']
  27. config_name = app.config['config_name']
  28. data = runtool(exp, root_dir, output_dir, config_name, mutate_num)
  29. print(data)
  30. return data
  31. if __name__ == '__main__':
  32. app.run()