import argparse
import os
import tools
import api
from app import app

cur_dirs = os.path.abspath(os.path.dirname(__file__))
save_dir = os.path.join(cur_dirs, 'outputs')
upload_dir = os.path.join(cur_dirs, "uploads")

app.config['UPLOAD_FOLDER'] = upload_dir


def init():
    if os.path.exists(upload_dir) is False:
        os.makedirs(upload_dir)
    api.set_options(upload_dir, save_dir)


def parse_args():
    parser = argparse.ArgumentParser(
        description='PP-HumanSeg inference for video')
    parser.add_argument(
        "--production",
        dest="production",
        help="production mode",
        action="store_true",
        required=False)
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()
    print("args: {}".format(args))
    init()
    tools.load_model()
    debug = False if args.production else True
    app.run(port=20201, host="0.0.0.0", debug=debug)
