Ejemplo n.º 1
0
def update_targetimage(targetimage_id):
    print(targetimage_id)
    targetimage = Targetimage.query.get_or_404(targetimage_id)
    form = CreateTargetImageForm()
    if form.validate_on_submit():
        if form.file.data:
            targetimage.file = save_item(form.file.data)
            targetimage.thumbnail = save_thumbnail(form.file.data)
        targetimage.name = form.name.data
        targetimage.age = form.age.data
        db.session.commit()
        flash(gettext('Your new image has been updated'), 'success')
        return redirect(
            url_for('analytics.update_targetimage',
                    targetimage_id=targetimage.id))
    elif request.method == 'GET':
        form.name.data = targetimage.name
        form.age.data = targetimage.age
    itemsall = Item.query.order_by(Item.date_posted.desc()).all()
    searchform = SearchItemForm()
    return render_template('create_targetimage.html',
                           title='Update Image',
                           form=form,
                           legend=gettext('Update image for target'),
                           itemsall=itemsall,
                           searchform=searchform)
Ejemplo n.º 2
0
def new_targetimage(target_id):
    target = Target.query.get_or_404(target_id)
    form = CreateTargetImageForm()
    if form.validate_on_submit():
        if form.file.data:
            file = save_item(form.file.data)
            thumbnail = save_thumbnail(form.file.data)
            targetimage = Targetimage(name=form.name.data,
                                      imagefortarget=target,
                                      file=file,
                                      thumbnail=thumbnail,
                                      age=form.age.data)
            db.session.add(targetimage)
            db.session.commit()
            flash(gettext('Your new image has been created'), 'success')
            return redirect(
                url_for('analytics.update_target', target_id=target.id))
    itemsall = Item.query.order_by(Item.date_posted.desc()).all()
    searchform = SearchItemForm()
    return render_template('create_targetimage.html',
                           title='New Image',
                           form=form,
                           legend=gettext('New image for target'),
                           itemsall=itemsall,
                           searchform=searchform)
Ejemplo n.º 3
0
def new_multipleitem():
    form = MultipleItemForm()

    if form.validate_on_submit():
        pics = request.files.getlist(form.item_files.name)
        if pics:
            current_user.multipleupload = len(pics)
            db.session.commit()
            founderror = False
            for pic in pics:
                filename = pic.filename
                try:
                    itemfile = save_item(pic)
                    thumbnailfile = save_thumbnail(pic)
                except Exception as e:
                    current_app.logger.warning('File {} of {}: {}'.format(
                        pic.filename, current_user.username, e))
                    founderror = True
                else:
                    itemname = form.itemname.data + " - " + filename
                    if len(itemname) > 35:
                        itemname = itemname[0:32] + "..."
                    item = Item(
                        item_file=itemfile,
                        itemname=itemname,
                        thumbnail=thumbnailfile,
                        owner=current_user,
                        analysis_keywords=form.analysis_keywords.data,
                        analysis_persons=form.analysis_persons.data,
                        analysis_celebs=form.analysis_celebs.data,
                        analysis_targets=form.analysis_targets.data,
                        analysis_text=form.analysis_text.data,
                        analysis_labels=form.analysis_labels.data,
                        analysis_threshold=form.analysis_threshold.data)
                    db.session.add(item)
                    db.session.commit()
                    try:
                        object_and_scene_detection_error = True
                        facial_analysis_error = True
                        celebrity_recognition_error = True
                        face_comparison_error = True
                        text_detection_error = True
                        unsafe_content_detection_error = True
                        # Object and scene detection - Keywords
                        object_and_scene_detection(item=item)
                        object_and_scene_detection_error = False
                        # Facial analysis - Persons
                        facial_analysis(item=item)
                        facial_analysis_error = False
                        # Celebrity recognition
                        celebrity_recognition(item=item)
                        celebrity_recognition_error = False
                        # Face comparision
                        face_comparison(item=item)
                        face_comparison_error = False
                        # Test in item
                        text_detection(item=item)
                        text_detection_error = False
                        # Image moderation
                        unsafe_content_detection(item=item)
                        unsafe_content_detection_error = False
                    except Exception:
                        current_app.logger.exception(
                            'Analysis item {} of {} incomplete: {} / {} / {} / {} / {} / {}'
                            .format(pic.filename, current_user.username,
                                    object_and_scene_detection_error,
                                    facial_analysis_error,
                                    celebrity_recognition_error,
                                    face_comparison_error,
                                    text_detection_error,
                                    unsafe_content_detection_error))
                        founderror = True
            if founderror:
                flash(
                    gettext(
                        'The new items could not be created and analysed completly'
                    ), 'danger')
            else:
                flash(gettext('Your new items have been created'), 'success')
            return redirect(url_for('main.home'))
    itemsall = Item.query.order_by(Item.date_posted.desc()).all()
    form.analysis_keywords.data = True
    form.analysis_threshold.data = 90
    searchform = SearchItemForm()
    return render_template('multiple_item.html',
                           title='New Items',
                           form=form,
                           legend=gettext('New Items'),
                           itemsall=itemsall,
                           searchform=searchform)
Ejemplo n.º 4
0
def update_item(item_id):
    item = Item.query.get_or_404(item_id)
    if item.owner != current_user:
        abort(403)
    form = CreateItemForm()
    if form.validate_on_submit():
        if form.item_file.data:
            try:
                item.item_file = save_item(form.item_file.data)
                item.thumbnail = save_thumbnail(form.item_file.data)
            except Exception as e:
                current_app.logger.warning('File {} of {}: {}'.format(
                    form.item_file.data, current_user.username, e))
                flash(gettext('The item cannot be updated for this file'),
                      'danger')
                return redirect(url_for('items.update_item', item_id=item.id))
        item.itemname = form.itemname.data
        item.analysis_keywords = form.analysis_keywords.data
        item.analysis_persons = form.analysis_persons.data
        item.analysis_celebs = form.analysis_celebs.data
        item.analysis_targets = form.analysis_targets.data
        item.analysis_text = form.analysis_text.data
        item.analysis_labels = form.analysis_labels.data
        item.analysis_threshold = form.analysis_threshold.data
        db.session.query(ItemKeyword).filter(
            ItemKeyword.item_id == item_id).delete()
        db.session.query(Person).filter(Person.item_id == item_id).delete()
        db.session.commit()
        try:
            object_and_scene_detection_error = True
            facial_analysis_error = True
            celebrity_recognition_error = True
            face_comparison_error = True
            text_detection_error = True
            unsafe_content_detection_error = True
            # Object and scene detection - Keywords
            object_and_scene_detection(item=item)
            object_and_scene_detection_error = False
            # Facial analysis - Persons
            facial_analysis(item=item)
            facial_analysis_error = False
            # Celebrity recognition
            celebrity_recognition(item=item)
            celebrity_recognition_error = False
            # Face comparision
            face_comparison(item=item)
            face_comparison_error = False
            # Test in item
            text_detection(item=item)
            text_detection_error = False
            # Image moderation
            unsafe_content_detection(item=item)
            unsafe_content_detection_error = False
        except Exception:
            current_app.logger.exception(
                'Analysis item {} of {} incomplete: {} / {} / {} / {} / {} / {}'
                .format(form.item_file.data, current_user.username,
                        object_and_scene_detection_error,
                        facial_analysis_error, celebrity_recognition_error,
                        face_comparison_error, text_detection_error,
                        unsafe_content_detection_error))
            flash(gettext('The item cannot be analysed completly'), 'danger')
        else:
            flash(gettext('Your item has been updated'), 'success')
        return redirect(url_for('items.item', item_id=item.id))
    elif request.method == 'GET':
        form.itemname.data = item.itemname
        form.item_file.data = item.item_file
        form.analysis_keywords.data = item.analysis_keywords
        form.analysis_persons.data = item.analysis_persons
        form.analysis_celebs.data = item.analysis_celebs
        form.analysis_targets.data = item.analysis_targets
        form.analysis_text.data = item.analysis_text
        form.analysis_labels.data = item.analysis_labels
        form.analysis_threshold.data = item.analysis_threshold
    itemsall = Item.query.order_by(Item.date_posted.desc()).all()
    itemkeywords = ItemKeyword.query.filter_by(itemin=item).all()
    persons = Person.query.filter_by(itemin=item)
    attributes = {}
    for person in persons:
        personattributes = PersonAttribute.query.filter_by(
            referenceperson=person).all()
        attributes[person.id] = personattributes
    searchform = SearchItemForm()
    return render_template('create_item.html',
                           title="Update Item",
                           form=form,
                           legend=gettext('Update Item'),
                           item=item,
                           itemsall=itemsall,
                           itemkeywords=itemkeywords,
                           persons=persons,
                           searchform=searchform)
Ejemplo n.º 5
0
def new_item():
    form = CreateItemForm()
    if form.validate_on_submit():
        if form.item_file.data:
            try:
                itemfile = save_item(form.item_file.data)
                thumbnailfile = save_thumbnail(form.item_file.data)
            except Exception as e:
                current_app.logger.warning('File {} of {}: {}'.format(
                    form.item_file.data, current_user.username, e))
                flash(gettext('No item can be created for this file'),
                      'danger')
                return redirect(url_for('items.new_item'))
            else:
                item = Item(item_file=itemfile,
                            itemname=form.itemname.data,
                            thumbnail=thumbnailfile,
                            owner=current_user,
                            analysis_keywords=form.analysis_keywords.data,
                            analysis_persons=form.analysis_persons.data,
                            analysis_celebs=form.analysis_celebs.data,
                            analysis_targets=form.analysis_targets.data,
                            analysis_text=form.analysis_text.data,
                            analysis_labels=form.analysis_labels.data,
                            analysis_threshold=form.analysis_threshold.data)
                db.session.add(item)
                db.session.commit()
                try:
                    object_and_scene_detection_error = True
                    facial_analysis_error = True
                    celebrity_recognition_error = True
                    face_comparison_error = True
                    text_detection_error = True
                    unsafe_content_detection_error = True
                    # Object and scene detection - Keywords
                    object_and_scene_detection(item=item)
                    object_and_scene_detection_error = False
                    # Facial analysis - Persons
                    facial_analysis(item=item)
                    facial_analysis_error = False
                    # Celebrity recognition
                    celebrity_recognition(item=item)
                    celebrity_recognition_error = False
                    # Face comparision
                    face_comparison(item=item)
                    face_comparison_error = False
                    # Test in item
                    text_detection(item=item)
                    text_detection_error = False
                    # Image moderation
                    unsafe_content_detection(item=item)
                    unsafe_content_detection_error = False
                except Exception:
                    current_app.logger.exception(
                        'Analysis item {} of {} incomplete: {} / {} / {} / {} / {} / {}'
                        .format(form.item_file.data, current_user.username,
                                object_and_scene_detection_error,
                                facial_analysis_error,
                                celebrity_recognition_error,
                                face_comparison_error, text_detection_error,
                                unsafe_content_detection_error))
                    flash(gettext('The item cannot be analysed completly'),
                          'danger')
                else:
                    flash(gettext('Your new item has been created'), 'success')
                return redirect(url_for('items.item', item_id=item.id))
    itemsall = Item.query.order_by(Item.date_posted.desc()).all()
    form.analysis_keywords.data = True
    form.analysis_threshold.data = 90
    searchform = SearchItemForm()
    return render_template('create_item.html',
                           title='New Item',
                           form=form,
                           legend=gettext('New Item'),
                           itemsall=itemsall,
                           searchform=searchform)