Exemple #1
0
def upload_pic(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        imageName = str(request.FILES['image'])
        print "Hello this is :"+imageName
        # print request.POST
        if form.is_valid():
            m = ExampleModel()
            m.model_pic = form.cleaned_data['image']
            m.save()

            im = imClassify.imClassify()
            imagePath = 'utilities/images/'+imageName
            resultList = im.main(imagePath)
            print  "THi is view ;;;;;; ------ ;;;;"
            print resultList

            # Considering only the first string
            # [['giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', 0.89233041], ['indri, indris, Indri indri, Indri brevicaudatus', 0.0085870409], ['lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', 0.0026423461], ['custard apple', 0.0014067066], ['earthstar', 0.0010706335]]
            nameOfTopic = resultList[0][0].split(",")[0]
            print nameOfTopic

            du = duckduckGo.duckduckGo()
            description = du.getInfo(nameOfTopic)

            print description

            # Now deleting the file
            if os.path.isfile(imagePath):
                os.remove(imagePath)

            return render(request,'result.html',{'imageName':nameOfTopic, 'description':description})
    return HttpResponseForbidden('allowed only via POST')
def new_example():
    """Add a new example"""
    form = ExampleForm()
    if form.validate_on_submit():
        example = ExampleModel(
                    example_id = form.example_id.data,
                    example_title = form.example_title.data,
                    added_by = users.get_current_user()
                    )
        example.put()
        flash(u'Example successfully saved.', 'success')
        return redirect(url_for('list_examples'))
    return render_template('new_example.html', form=form)
Exemple #3
0
def upload_pic(request):
  
  c = {}
  c.update(csrf(request))  
  script_args['c'] = c
  
  if request.method == 'POST':
    form = ImageUploadForm(request.POST, request.FILES)
    if form.is_valid():
      m = ExampleModel()
      m.model_pic = form.cleaned_data['image']
      m.save()
      return HttpResponse('image upload success')
    
  return render_to_response("emc/upload_pic.html", c)    
Exemple #4
0
    def dispatch_request(self):
        if request.method == "POST":

            form = request.get_json()
            example_id = form['example_id']

            if example_id:
                example = ExampleModel.get_by_id( int(example_id) )

                if example:
                    try:
                        example.example_name = form['example_name']
                        example.example_description = form['example_description']

                        example.put()
                        return jsonify(result = {'status':'ok'})

                    except CapabilityDisabledError:
                        return jsonify(result = {'status':'Error to update'})

                else:
                    return jsonify(result = {'status':'NOT item found'})

            else:
                return jsonify(result = {'status':'no example_example send'})

        else:
            return jsonify(result = {'status':'NOT is correct method'})
Exemple #5
0
    def on_post(self, req, resp):
        email = req.get_json('email',
                             dtype=str,
                             min=6,
                             max=32,
                             default="*****@*****.**")
        name = req.get_json('name',
                            dtype=str,
                            min=1,
                            max=16,
                            default="Andrei Regiani")

        row = ExampleModel(email=email, name=name)
        row.save()

        resp.json = {'id': str(row.id)}
        resp.status = falcon.HTTP_201
def new_example():
    """Add a new example, detecting whether or not App Engine is in read-only mode."""
    form = ExampleForm()
    if form.validate_on_submit():
        example = ExampleModel(
                    example_id = form.example_id.data,
                    example_title = form.example_title.data,
                    added_by = users.get_current_user()
                    )
        try:
            example.put()
            flash(u'Example successfully saved.', 'success')
            return redirect(url_for('list_examples'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
            return redirect(url_for('list_examples'))
    return render_template('new_example.html', form=form)
Exemple #7
0
def delete_example(example_id):
    example = ExampleModel.get_by_id(example_id)
    try:
        example.key.delete()
        flash(u'Example %s successfully deleted.' % example_id, 'success')
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
    return redirect(url_for('list_examples'))
 def dispatch_request(self):
     examples = ExampleModel.query()
     form = ExampleForm()
     if form.validate_on_submit():
         example = ExampleModel(
             example_name=form.example_name.data,
             example_description=form.example_description.data,
             added_by=users.get_current_user()
         )
         try:
             example.put()
             example_id = example.key.id()
             flash(u'Example %s successfully saved.' % example_id, 'success')
             return redirect(url_for('list_examples'))
         except CapabilityDisabledError:
             flash(u'App Engine Datastore is currently in read-only mode.', 'info')
             return redirect(url_for('list_examples'))
     return render_template('list_examples.html', examples=examples, form=form)
def quick_list():
    """Test function for my simple form"""
    form = QuickListForm()
    examples = ExampleModel.query()
    form.cmb_map.choices = []
    for example in examples:
        form.cmb_map.choices.append((example.example_description, example.example_name))

    return render_template('quick_list.html', form=form)
 def dispatch_request(self, example_id):
     example = ExampleModel.get_by_id(example_id)
     if request.method == "POST":
         try:
             example.key.delete()
             flash(u"Example %s successfully deleted." % example_id, "success")
             return redirect(url_for("list_examples"))
         except CapabilityDisabledError:
             flash(u"App Engine Datastore is currently in read-only mode.", "info")
             return redirect(url_for("list_examples"))
def delete_example(example_id):
    """Delete an example object"""
    example = ExampleModel.get_by_id(example_id)
    try:
        example.key.delete()
        flash(u'Example %s successfully deleted.' % example_id, 'success')
        return redirect(url_for('list_examples'))
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
        return redirect(url_for('list_examples'))
Exemple #12
0
def delete_dimension(dimension_id):
    """Delete an dimension object"""
    dimension = ExampleModel.get_by_id(dimension_id)
    try:
        dimension.key.delete()
        flash(u'Example %s successfully deleted.' % dimension_id, 'success')
        return redirect(url_for('list_dimensions'))
    except CapabilityDisabledError:
        flash(u'App Engine Datastore is currently in read-only mode.', 'info')
        return redirect(url_for('list_dimensions'))
Exemple #13
0
def list_examples():
    """List all examples"""
    examples = ExampleModel.all()
    form = ExampleForm()
    if form.validate_on_submit():
        example = ExampleModel(
            example_name=form.example_name.data,
            example_description=form.example_description.data,
            added_by=users.get_current_user(),
        )
        try:
            example.put()
            example_id = example.key().id()
            flash(u"Example %s successfully saved." % example_id, "success")
            return redirect(url_for("list_examples"))
        except CapabilityDisabledError:
            flash(u"App Engine Datastore is currently in read-only mode.", "info")
            return redirect(url_for("list_examples"))
    return render_template("list_examples.html", examples=examples, form=form)
Exemple #14
0
def delete_example(example_id):
    """Delete an example object"""
    example = ExampleModel.get_by_id(example_id)
    try:
        example.delete()
        flash(u"Example %s successfully deleted." % example_id, "success")
        return redirect(url_for("list_examples"))
    except CapabilityDisabledError:
        flash(u"App Engine Datastore is currently in read-only mode.", "info")
        return redirect(url_for("list_examples"))
 def dispatch_request(self, example_id):
     example = ExampleModel.get_by_id(example_id)
     if request.method == "POST":
         try:
             example.key.delete()
             cache.clear()
             flash(u'Example %s successfully deleted.' % example_id, 'success')
             return redirect(url_for('list_examples'))
         except CapabilityDisabledError:
             flash(u'App Engine Datastore is currently in read-only mode.', 'info')
             return redirect(url_for('list_examples'))
def edit_example(example_id):
    example = ExampleModel.get_by_id(example_id)
    form = ExampleForm(obj=example)
    if request.method == "POST":
        if form.validate_on_submit():
            example.example_name = form.data.get('example_name')
            example.example_description = form.data.get('example_description')
            example.put()
            flash(u'Example %s successfully saved.' % example_id, 'success')
            return redirect(url_for('list_examples'))
    return render_template('edit_example.html', example=example, form=form)
Exemple #17
0
    def dispatch_request(self):

        if request.method == "POST":
            form = request.get_json()
            example = ExampleModel(
                example_name = form['example_name'],
                example_description = form['example_description'],
                added_by = users.get_current_user()
            )

            try:
                example.put()
                example_id = example.key.id()
                return jsonify(result = {'status':'ok'})

            except CapabilityDisabledError:
                return jsonify(result = {'status':'DONT cant save'})

        else:
            return jsonify(result = {'status':'NOT is correct method'})
Exemple #18
0
def edit_example(example_id):
    example = ExampleModel.get_by_id(example_id)
    form = ExampleForm(obj=example)
    if request.method == "POST":
        if form.validate_on_submit():
            example.example_name = form.data.get('example_name')
            example.example_description = form.data.get('example_description')
            example.put()
            flash(u'Example %s successfully saved.' % example_id, 'success')
            return redirect(url_for('list_examples'))
    return render_template('edit_example.html', example=example, form=form)
Exemple #19
0
def edit_example(example_id):
    example = ExampleModel.get_by_id(example_id)
    form = ExampleForm(obj=example)
    if request.method == "POST":
        if form.validate_on_submit():
            example.example_name = form.data.get("example_name")
            example.example_description = form.data.get("example_description")
            example.put()
            flash(u"Example %s successfully saved." % example_id, "success")
            return redirect(url_for("list_examples"))
    return render_template("edit_example.html", example=example, form=form)
Exemple #20
0
 def dispatch_request(self, example_id):
     example = ExampleModel.get_by_id(example_id)
     if request.method == "POST":
         try:
             example.key.delete()
             flash(u'Example %s successfully deleted.' % example_id,
                   'success')
             return redirect(url_for('list_examples'))
         except CapabilityDisabledError:
             flash(u'App Engine Datastore is currently in read-only mode.',
                   'info')
             return redirect(url_for('list_examples'))
Exemple #21
0
def dashboard():
    """List all examples"""
    email = request.args.get('email',"")
    profile = request.args.get('profile',"")
    logging.info("email=%s profile=%s",email,profile)
    examples = ExampleModel.query()
    form = ExampleForm()
    if form.validate_on_submit():
        example = ExampleModel(
            example_name=form.example_name.data,
            example_description=form.example_description.data,
            added_by=users.get_current_user()
        )
        try:
            example.put()
            example_id = example.key.id()
            flash(u'Example %s successfully saved.' % example_id, 'success')
            return redirect(url_for('dashboard'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('dashboard'))
    return render_template('dashboard.html', examples=examples, form=form)
def cached_examples():
    """This view should be cached for 60 sec"""
    examples = ExampleModel.query()
    return render_template('list_examples_cached.html', examples=examples)
Exemple #23
0
def upload_pic(request):

    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            # os.remove(file) for file in os.listdir('path/to/directory') if file.endswith('.png')
            for file in os.listdir(os.path.join(BASE_DIR, 'media', 'img')):
                if (file.endswith('.jpg')):
                    os.remove(os.path.join(BASE_DIR, 'media', 'img', file))
            for file in os.listdir(os.path.join(BASE_DIR, 'static', 'img')):
                if (file.endswith('.jpg')):
                    os.remove(os.path.join(BASE_DIR, 'static', 'img', file))
            m = ExampleModel()
            m.model_pic = form.cleaned_data['image']
            m.save()
            for file in os.listdir(os.path.join(BASE_DIR, 'media', 'img')):
                if (file.endswith('.jpg')):
                    shutil.move(
                        os.path.join(BASE_DIR, 'media', 'img', file),
                        os.path.join(BASE_DIR, 'media', 'img', 'main.jpg'))
                    shutil.copy(
                        os.path.join(BASE_DIR, 'media', 'img', 'main.jpg'),
                        os.path.join(BASE_DIR, 'static', 'img', 'main.jpg'))
            pathForImage = os.path.join(BASE_DIR, 'static', 'img', 'main.jpg')
            mainImage = cv2.imread(pathForImage)
            p = subprocess.Popen(
                '/usr/local/src/openalpr/src/build/alpr -c kz -p kz -j ' +
                pathForImage,
                stdout=subprocess.PIPE,
                shell=True)
            (output, err) = p.communicate()
            p_status = p.wait()
            main_out = output.split('\n')[0]
            data = (json.loads(main_out))['results']
            # print(data)
            if (len(data) == 0):
                data = {'plateNumber': 'НОМЕР БЫЛ НЕ НАЙДЕН'}
                return render(request, 'second.html', data)
            else:
                coordinates = data[0]['coordinates']
                top_left = coordinates[1]
                bottom_right = coordinates[3]
                y1 = top_left['y']
                x1 = top_left['x']

                y2 = bottom_right['y']
                x2 = bottom_right['x']

                cv2.rectangle(mainImage, (x1, int(y1)), (x2, int(y2)),
                              (0, 255, 0), 1)
                cv2.imwrite(pathForImage, mainImage)
                plates = data[0]['candidates']
                plate_number = (data[0]['candidates'][0]['plate'])

                best_predicted = data[0]['candidates'][0]['plate']
                best_predicted_by_pattern = []
                for plate in plates:
                    if (plate['matches_template'] == 1):
                        best_predicted_by_pattern.append(plate['plate'])
                if (len(best_predicted_by_pattern) != 0):
                    best_predicted = best_predicted_by_pattern[0]
                data = {'plateNumber': best_predicted}
                return render(request, 'second.html', data)
    return HttpResponseForbidden('allowed only via POST')
Exemple #24
0
def cached_dimensions():
    """This view should be cached for 60 sec"""
    dimensions = ExampleModel.query()
    return render_template('list_dimensions_cached.html', dimensions=dimensions)
Exemple #25
0
def cached_examples():
    """This view should be cached for 60 sec"""
    examples = ExampleModel.query()
    return render_template('list_examples_cached.html', examples=examples)
Exemple #26
0
 def dispatch_request(self):
     examples = ExampleModel.query()
     collective = {'name': 'Viva Dance', 'bucket': 'viva'}
     return render_template('collectives/collective.html', examples=examples, collective=collective)
def train_model(data_set_identifier, train_file, val_file, learning_rate,
                minibatch_size):
    set_protien_experiments_id(data_set_identifier, learning_rate,
                               minibatch_size)

    train_loader = contruct_data_loader_from_disk(train_file, minibatch_size)
    validation_loader = contruct_data_loader_from_disk(val_file,
                                                       minibatch_size)
    validation_dataset_size = validation_loader.dataset.__len__()

    model = ExampleModel(9, "ONEHOT", minibatch_size, use_gpu=use_gpu)

    optimizer = optim.Adam(model.parameters(), lr=learning_rate)

    # plot settings
    if live_plot:
        plt.ion()
    fig = plt.figure()
    sample_num = list()
    train_loss_values = list()
    validation_loss_values = list()

    best_model_loss = 1.1
    best_model_minibatch_time = None
    best_model_path = None
    stopping_condition_met = False
    minibatches_proccesed = 0

    while not stopping_condition_met:
        optimizer.zero_grad()
        model.zero_grad()
        loss_tracker = np.zeros(0)
        for minibatch_id, training_minibatch in enumerate(train_loader, 0):
            minibatches_proccesed += 1
            primary_sequence, tertiary_positions, mask = training_minibatch
            start_compute_loss = time.time()
            loss = model.neg_log_likelihood(primary_sequence,
                                            tertiary_positions)
            write_out("Train loss:", float(loss))
            start_compute_grad = time.time()
            loss.backward()
            loss_tracker = np.append(loss_tracker, float(loss))
            end = time.time()
            write_out("Loss time:", start_compute_grad - start_compute_loss,
                      "Grad time:", end - start_compute_grad)
            optimizer.step()
            optimizer.zero_grad()
            model.zero_grad()

            # for every eval_interval samples, plot performance on the validation set
            if minibatches_proccesed % eval_interval == 0:

                train_loss = loss_tracker.mean()
                loss_tracker = np.zeros(0)
                validation_loss, data_total = test_eval_model(
                    validation_loader, model)
                prim = data_total[0][0]
                pos = data_total[0][1].transpose(0, 1).contiguous().view(-1, 3)
                pos_predicted = data_total[0][2].transpose(
                    0, 1).contiguous().view(-1, 3)
                write_to_pdb_strcture(pos, prim, "test")
                print(pos)
                # cmd.load("output/protein_test.pdb")
                write_to_pdb_strcture(pos_predicted.detach(), prim,
                                      "test_pred")
                if validation_loss < best_model_loss:
                    best_model_loss = validation_loss
                    best_model_minibatch_time = minibatches_proccesed
                    best_model_path = save_model_on_disk_torch_version(model)

                write_out("Validation loss:", validation_loss, "Train loss:",
                          train_loss)
                write_out("Best model so far (label loss): ", validation_loss,
                          "at time", best_model_minibatch_time)
                write_out("Best model stored at " + best_model_path)
                write_out("Minibatches processed:", minibatches_proccesed)
                sample_num.append(minibatches_proccesed)
                train_loss_values.append(train_loss)
                validation_loss_values.append(validation_loss)
                if live_plot:
                    drawnow(
                        draw_plot(fig, plt, validation_dataset_size,
                                  sample_num, train_loss_values,
                                  validation_loss_values))

                if minibatches_proccesed > minimum_updates and minibatches_proccesed > best_model_minibatch_time * 2:
                    stopping_condition_met = True
                    break
    logs(best_model_loss)
    return best_model_path
Exemple #28
0
    def dispatch_request(self):
        examples = ExampleModel.query()

        return render_template('ini.html', examples=examples )
Exemple #29
0
 def dispatch_request(self):
     examples = ExampleModel.query()
     collective = {'name': 'Степ студия', 'bucket': 'step'}
     return render_template('collectives/collective.html', examples=examples, collective=collective)
Exemple #30
0
 def dispatch_request(self):
     examples = ExampleModel.query()
     collective = {'name': 'Арлекин', 'bucket': 'arlekin'}
     return render_template('collectives/collective.html', examples=examples, collective=collective)
    def dispatch_request(self):

        examples = ExampleModel.query()
        return render_template('list_examples_cached.html', examples=examples)
def get_random_entry():
	entry = ExampleModel()
	entry.name = get_random_sentence().capitalize()
	entry.number = randint(1, 10)
	entry.description = get_random_sentence(10)
	return entry
Exemple #33
0
    def dispatch_request(self):
        list = ExampleModel.query().fetch()
        list = to_dict(list)

        return jsonify(results = list)
def list_examples():
    """List all examples"""
    examples = ExampleModel.all()
    return render_template('list_examples.html', examples=examples)
Exemple #35
0
def train_model(data_set_identifier, train_file, val_file, learning_rate,
                minibatch_size):
    set_experiment_id(data_set_identifier, learning_rate, minibatch_size)

    train_loader = contruct_dataloader_from_disk(train_file, minibatch_size)
    validation_loader = contruct_dataloader_from_disk(val_file, minibatch_size)
    validation_dataset_size = validation_loader.dataset.__len__()

    model = ExampleModel(21, minibatch_size,
                         use_gpu=use_gpu)  # embed size = 21

    # TODO: is soft_to_angle.parameters() included here?
    optimizer = optim.Adam(model.parameters(), lr=learning_rate)

    sample_num = list()
    train_loss_values = list()
    validation_loss_values = list()
    rmsd_avg_values = list()
    drmsd_avg_values = list()

    best_model_loss = 1.1
    best_model_minibatch_time = None
    best_model_path = None
    stopping_condition_met = False
    minibatches_proccesed = 0

    while not stopping_condition_met:
        optimizer.zero_grad()
        model.zero_grad()
        loss_tracker = np.zeros(0)
        for minibatch_id, training_minibatch in enumerate(train_loader, 0):
            minibatches_proccesed += 1
            primary_sequence, tertiary_positions, mask = training_minibatch
            start_compute_loss = time.time()
            loss = model.compute_loss(primary_sequence, tertiary_positions)
            write_out("Train loss:", float(loss))
            start_compute_grad = time.time()
            loss.backward()
            loss_tracker = np.append(loss_tracker, float(loss))
            end = time.time()
            write_out("Loss time:", start_compute_grad - start_compute_loss,
                      "Grad time:", end - start_compute_grad)
            optimizer.step()
            optimizer.zero_grad()
            model.zero_grad()

            # for every eval_interval samples, plot performance on the validation set
            if minibatches_proccesed % args.eval_interval == 0:

                train_loss = loss_tracker.mean()
                loss_tracker = np.zeros(0)
                validation_loss, data_total, rmsd_avg, drmsd_avg = evaluate_model(
                    validation_loader, model)
                prim = data_total[0][0]
                pos = data_total[0][1]
                (aa_list, phi_list, psi_list,
                 omega_list) = calculate_dihedral_angels(prim, pos)
                write_to_pdb(
                    get_structure_from_angles(aa_list, phi_list[1:],
                                              psi_list[:-1], omega_list[:-1]),
                    "test")
                cmd.load("output/protein_test.pdb")
                write_to_pdb(data_total[0][3], "test_pred")
                cmd.load("output/protein_test_pred.pdb")
                cmd.forward()
                cmd.orient()
                if validation_loss < best_model_loss:
                    best_model_loss = validation_loss
                    best_model_minibatch_time = minibatches_proccesed
                    best_model_path = write_model_to_disk(model)

                write_out("Validation loss:", validation_loss, "Train loss:",
                          train_loss)
                write_out("Best model so far (label loss): ", validation_loss,
                          "at time", best_model_minibatch_time)
                write_out("Best model stored at " + best_model_path)
                write_out("Minibatches processed:", minibatches_proccesed)
                sample_num.append(minibatches_proccesed)
                train_loss_values.append(train_loss)
                validation_loss_values.append(validation_loss)
                rmsd_avg_values.append(rmsd_avg)
                drmsd_avg_values.append(drmsd_avg)
                if args.live_plot:
                    data = {}
                    data["validation_dataset_size"] = validation_dataset_size
                    data["sample_num"] = sample_num
                    data["train_loss_values"] = train_loss_values
                    data["validation_loss_values"] = validation_loss_values
                    data["phi_actual"] = list(
                        [math.degrees(float(v)) for v in phi_list[1:]])
                    data["psi_actual"] = list(
                        [math.degrees(float(v)) for v in psi_list[:-1]])
                    data["phi_predicted"] = list([
                        math.degrees(float(v)) for v in data_total[0]
                        [2].detach().transpose(0, 1)[0][1:]
                    ])
                    data["psi_predicted"] = list([
                        math.degrees(float(v)) for v in data_total[0]
                        [2].detach().transpose(0, 1)[1][:-1]
                    ])
                    data["drmsd_avg"] = drmsd_avg_values
                    data["rmsd_avg"] = rmsd_avg_values
                    res = requests.post('http://localhost:5000/graph',
                                        json=data)
                    if res.ok:
                        print(res.json())

                if minibatches_proccesed > args.minimum_updates and minibatches_proccesed > best_model_minibatch_time * 2:
                    stopping_condition_met = True
                    break
    write_result_summary(best_model_loss)
    return best_model_path
Exemple #36
0
 def dispatch_request(self):
     examples = ExampleModel.query()
     collective = {'name': 'Павел Смирнов', 'bucket': 'smirnov'}
     return render_template('collectives/collective.html', examples=examples, collective=collective)