Exemplo n.º 1
0
def validate_input():
    headers, payload = request.headers, request.json
    if constants.WINDOW_BEGIN_KEY not in headers or not headers[
            constants.WINDOW_BEGIN_KEY]:
        raise JsonSchemaException('Header must contains "JANELA_INICIO"')
    if constants.WINDOW_END_KEY not in headers or not headers[
            constants.WINDOW_END_KEY]:
        raise JsonSchemaException('Header must contains "JANELA_FIM"')
    if payload is None or not payload:
        raise JsonSchemaException('Payload must not be empty')
    validation.validate(payload)
Exemplo n.º 2
0
 def assertValidateNoprogress(self, a, b):
     self.assertEqual(
         validate(a, b), VALIDATE_NOPROGRESS, 'Validation '
         'did detect progress or failed for %s => %s' % (a, b))
Exemplo n.º 3
0
 def assertValidateFailure(self, a, b):
     self.assertEqual(validate(a, b), VALIDATE_FAILURE,
                      'Validation dit not fail: %s => %s' % (a, b))
Exemplo n.º 4
0
 def assertValidateSuccess(self, a, b):
     self.assertEqual(validate(a, b), VALIDATE_SUCCESS,
                      'Validation failed: %s !=> %s' % (a, b))
Exemplo n.º 5
0
def create():
    if request.method == "POST":

        #Additional posting options BOOLEAN FLAGs
        post_option = request.form.get('post_option')
        if post_option is None:
            post_option = "None"

        #image upload
        if 'file' not in request.files:
            flash('No file part.')
            return redirect(request.url)

        file = request.files['file']

        if file.filename == '':
            flash('No file selected.')
            return redirect(request.url)

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(
                os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
            image = filename  #record proper information
            img_src = cv2.imread('src/static/images/' + filename)
            img_src = cv2.cvtColor(img_src, cv2.COLOR_BGR2RGB)

        body = request.form['body']

        #automatically generated
        cred = "Source: " + g.user['username']
        fingerprint = fp2text(gen_fp(img_src, 100, 1))

        error = None

        if not body:
            error = "Post requires text."

        #VALIDATION
        db = get_db()
        ticket = validate(text2fp(fingerprint), g.user['id'], db)
        if not bool(ticket[0]):
            error = ticket[1]

        if ticket[0] == "sponsor":
            error = None
            post_option = "sponsor"

        if error is not None:
            flash(error)

        else:
            db = get_db()
            db.execute(
                'INSERT INTO post (author_id, image, body, cred, fingerprint, post_type)'  #post_type: 'sponsor'
                ' VALUES (?,?,?,?,?,?)',
                (g.user['id'], image, body, cred, fingerprint, post_option))
            db.commit()
            return redirect(url_for('upload.index'))

    return render_template('create.html')
from tqdm import tqdm
import numpy as np
import neptune
from pathlib import Path

from src.trainer import create_trainer, create_model
from src.validation import validate

tokenizer = load_tokenizer("artifacts")

model = create_model()

neptune.init("oversbyg/cook-mlm")
neptune.create_experiment(name="example")

trainer = create_trainer(tokenizer, model)

for epoch in range(40):
    validation_result = validate(model, tokenizer)[0]

    neptune.log_metric("top1", validation_result)
    trainer.save_model("./artifacts")

    trainer.train()

    shuffle_data()
    trainer = create_trainer(tokenizer, model)

for file in Path("./artifacts").iterdir():
    neptune.log_artifact(str(file))
Exemplo n.º 7
0
 def assertValidateNoprogress(self, a, b):
     self.assertEqual(validate(a, b), VALIDATE_NOPROGRESS, 'Validation '
             'did detect progress or failed for %s => %s' % (a, b))
Exemplo n.º 8
0
 def assertValidateFailure(self, a, b):
     self.assertEqual(validate(a, b), VALIDATE_FAILURE,
                      'Validation dit not fail: %s => %s' % (a, b))
Exemplo n.º 9
0
 def assertValidateSuccess(self, a, b):
     self.assertEqual(validate(a, b), VALIDATE_SUCCESS,
                      'Validation failed: %s !=> %s' % (a, b))