<commit_before>from flask import render_template, Blueprint, request, redirect, url_for, abort, jsonify, g, make_response, send_file
from flask_login import login_user, current_user, login_required, logout_user
from project import db, auth, auth_token, app, images
import uuid
import os
import zipfile
import json
import shutil
from werkzeug import secure_filename
from project.exceptions import RequestException, RequestExceptionPlus
from .libs import context, train
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from project.models import TrainingSession, User, Error
from project import db, app

training_api_blueprint = Blueprint('training_api', __name__)

# the root path is : /home/flask/app/web

#============================================================================================
# web api


#============================================================================================
# TRAIN FEATURES
#============================================================================================
# receive a features' zip & train them:
#
# OPERATIONS
# get session & user IDs
# check, prepare file system and get submitted file
# => I create           instance/users_data/APIKEY/train_data/training_sessionid/data
# save zip 
# => I copy zip to      instance/users_data/APIKEY/train_data/training_sessionid/data.zip
# => I extract zip to   instance/users_data/APIKEY/train_data/training_sessionid/data
# copy json from        instance/..../training_sessionid/data => instance/..../training_sessionid/vocabulary.json
# read from it the nModelType
# add present session into the db
# start training :      train.train_net(session_data, session_path, session_uid, voicebank_vocabulary_path, True)
#
@training_api_blueprint.route('/api/v1/training-sessions', methods=['POST'])
def add_training_session():

    cdir = os.getcwd()
    param_file = os.path.join('project', 'training_api', 'params', 'ff_pure_user_trainparams.json')
    existfile = str(os.path.exists(param_file))
    raise RequestException(param_file + ':' + param_file + ":" + existfile)

    if 'file' not in request.files or request.files['file'].filename == '':
        msg = 'ERROR: no file in request'
        raise RequestException(msg)

    # list of available commands
    voicebank_vocabulary_path = os.path.join(app.instance_path, 'voicebank_commands.json')

    # get session & user IDs
    userkey = current_user.get_key()<commit_msg>test path2<commit_after>from flask import render_template, Blueprint, request, redirect, url_for, abort, jsonify, g, make_response, send_file
from flask_login import login_user, current_user, login_required, logout_user
from project import db, auth, auth_token, app, images
import uuid
import os
import zipfile
import json
import shutil
from werkzeug import secure_filename
from project.exceptions import RequestException, RequestExceptionPlus
from .libs import context, train
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from project.models import TrainingSession, User, Error
from project import db, app

training_api_blueprint = Blueprint('training_api', __name__)

# the root path is : /home/flask/app/web

#============================================================================================
# web api


#============================================================================================
# TRAIN FEATURES
#============================================================================================
# receive a features' zip & train them:
#
# OPERATIONS
# get session & user IDs
# check, prepare file system and get submitted file
# => I create           instance/users_data/APIKEY/train_data/training_sessionid/data
# save zip 
# => I copy zip to      instance/users_data/APIKEY/train_data/training_sessionid/data.zip
# => I extract zip to   instance/users_data/APIKEY/train_data/training_sessionid/data
# copy json from        instance/..../training_sessionid/data => instance/..../training_sessionid/vocabulary.json
# read from it the nModelType
# add present session into the db
# start training :      train.train_net(session_data, session_path, session_uid, voicebank_vocabulary_path, True)
#
@training_api_blueprint.route('/api/v1/training-sessions', methods=['POST'])
def add_training_session():

    cdir = os.getcwd()
    param_file1 = os.path.join('project', 'training_api', 'params', 'ff_pure_user_trainparams.json')
    param_file2 = os.path.join('web', 'project', 'training_api', 'params', 'ff_pure_user_trainparams.json')
    return jsonify({'param_file1': param_file1, 'param_file2': param_file2, 'cdir':cdir, 'res':os.path.exists(param_file)}), 201, {'Location': training_session.get_url()}

    if 'file' not in request.files or request.files['file'].filename == '':
        msg = 'ERROR: no file in request'
        raise RequestException(msg)

    # list of available commands
    voicebank_vocabulary_path = os.path.join(app.instance_path, 'voicebank_commands.json')

    # get session & user IDs
    userkey = current_user.get_key()
{'fraction_non_alphanumeric': 0.19719976336028397, 'fraction_numerical': 0.0023663971603234074, 'mean_word_length': 5.587012987012987, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1345129', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1368, 'n_words': 380}