Exemple #1
0
def manage_job(error_message):
    print('jobs')
    print(app.task_queue.job_ids)
    dict_status = get_file_status()
    dict_valid_status = get_valid_status()
    print(app.job_file2id)
    print(dict_status)
    form = SelectConfigForm()
    form.select_config.choices = get_options(get_configs())
    form.select_data.choices = get_options(get_files())
    if request.method == 'POST':
        print("form:", request.form)
        data_choices = dict(get_options(get_files()))
        config_choices = dict(get_options(get_configs()))
        print(get_configs())
        select_config = config_choices.get(form.select_config.data)
        select_data = data_choices.get(form.select_data.data)
        print('data', select_data)
        print('config:', select_config)
        if form.submit.data:
            return redirect(
                url_for('train_model',
                        filename=select_data,
                        config=select_config))
        elif form.submit_valid.data:
            return redirect(
                url_for('valid_model',
                        filename=select_data,
                        config=select_config))
    return render_template('jobs.html',
                           form=form,
                           dict_status=dict_status,
                           dict_valid_status=dict_valid_status,
                           errors=error_message)
Exemple #2
0
def manage_model():
    error_message = ''
    model_dict = list_model_dir()
    form = UploadModelForm()
    form.select_config.choices = get_options(get_configs())
    if form.validate_on_submit() and request.method == 'POST':
        f = form.archive.data
        filename = secure_filename(f.filename)
        config_choices = dict(get_options(get_configs()))
        select_config = config_choices.get(form.select_config.data)
        trainset = 'Upload'
        model_dir = add_model(trainset, select_config)
        print('upload model:', select_config, filename, model_dir)
        if model_dir is None:
            error_message = 'Model already exists.'
            return redirect(url_for('manage_model'))
        else:
            extract_path = os.path.join(app.config['TMP_FOLDER'], filename)
            f.save(extract_path)
            print(extract_path,
                  os.path.join(app.config['MODEL_FOLDER'], model_dir))
            extract_file(extract_path,
                         os.path.join(app.config['MODEL_FOLDER'], model_dir))
            return redirect(url_for('manage_model'))
        # if (trainset, select_config) in model_dict:
        # return redirect(url_for('manage_data'))
    return render_template('models.html',
                           form=form,
                           dict_model=model_dict,
                           error_message=error_message)
Exemple #3
0
def manage_model_list():
    trainset = request.args.get('trainset', None)
    config = request.args.get('config', None)
    model_dir = get_model_dir(trainset, config)
    file_list = get_model_list(model_dir)
    print(file_list)
    form = SelectEvalForm()
    form.select_model.choices = get_options(file_list)
    form.select_test.choices = get_options(get_files())
    if request.method == 'POST':
        print("form:", request.form)
        data_choices = dict(get_options(get_files()))
        model_choices = dict(get_options(file_list))
        print(get_configs())
        select_model = model_choices.get(form.select_model.data)

        select_test = data_choices.get(form.select_test.data)
        print('model', select_model)
        print('test:', select_test)
        return redirect(
            url_for('eval_model',
                    trainname=trainset,
                    config=config,
                    testname=select_test,
                    modelname=select_model))
    return render_template('model_download.html',
                           form=form,
                           trainname=trainset,
                           config=config,
                           files_list=file_list)
Exemple #4
0
def manage_configs(error_message):
    print('errors:  %s' % error_message)
    configs_list = get_configs()
    form = UploadConfigForm()
    f = form.archive.data
    errors = error_message.split('\n')
    print(errors)
    print(error_message)
    if form.validate_on_submit():
        content = f.read()
        errors = validate_string(content)
        print(errors)
        if len(errors) > 0:
            print('print_error')
            return redirect(
                url_for('manage_configs', error_message='\n'.join(errors)))
        else:
            filename = secure_filename(f.filename)
            prefix = filename.rsplit('.')[0]
            filename = rename_file(prefix, '.json', configs_list)
            with open(os.path.join(app.config['CONFIG_FOLDER'], filename),
                      'w',
                      encoding='utf-8') as f_:
                json.dump(json.loads(content.decode('ascii')), f_)
            return redirect(url_for('manage_configs'))
    return render_template('configs.html',
                           errors=errors,
                           form=form,
                           files_list=configs_list)