Пример #1
0
def image():
    uuid_return = str(uuid.uuid4())
    output_filename = uuid_return + ".jpg"

    data = request.json
    save_image(image_with_text(data['name']), ("temp/" + output_filename))
    return jsonify({'filename': uuid_return})
Пример #2
0
def api_add_report():
    if not utils.verify_digest(flask.request.data,
                               flask.request.headers["Authorization"]):
        app.logger.warning("Failed HMAC Auth")
        flask.abort(401)

    payload = flask.request.get_json()
    agent_id = payload["agent"].strip()

    if utils.is_dict_empty(["agent"], payload):
        app.logger.warning("Mandatory fields empty")
        flask.abort(404)

    db_agent = db.get_agent(agent_id)
    if agent is None:
        #TODO: replace with API error instead
        app.logger.warning("Attempted to upload report for nonexistent agent")
        flask.abort(404)

    #TODO: replace with proper short unique id generation
    report_id = utils.generate_short_uuid(
        str(random.random() * 1000) + str(payload["time"]) + agent_id, 8)

    db.add_report(report_id, payload["time"], db_agent["location"], agent_id)

    for report_image in payload["images"]:
        image_id = report_id + "_" + report_image["location"]

        try:
            images.save_image(image_id, report_image["image"],
                              images.ImageType.REPORT)
            db.add_report_image(image_id, report_image["location"], 0,
                                report_id)

            #thumbnail image for smaller version for dashboard
            images.save_image(image_id + ".thumb", report_image["image"],
                              images.ImageType.REPORT_THUMB)
        except (KeyError, IOError):
            flask.abort(500)

    return "", 200
Пример #3
0
def sync_db():
    images_recovered = 0
    images_deleted = 0

    conn, c = connect_to_db()
    c.execute("SELECT staticName, url FROM images")
    image_database = c.fetchall()

    #clean database
    for row in image_database:
        filename = row[0]
        url = row[1]

        full_image_path = os.path.join(photos_path, filename)
        if not os.path.isfile(full_image_path):
            try:
                images.save_image(url, filename=filename)
                images_recovered += 1
                print(filename, "recovered")
            except Exception as e:
                print(e)
                c.execute("DELETE FROM images WHERE staticName=?",
                          (filename, ))
                images_deleted += 1
                print(filename, "deleted")

    #clean images directory
    files = os.listdir(photos_path)
    for filename in files:
        for ext in pic_ext:
            if filename.endswith(ext):
                c.execute("SELECT staticName FROM images WHERE staticName=?",
                          (filename, ))
                if c.rowcount == 0:
                    images.delete_image(filename)
                    images_deleted += 1
                    print(filename, "deleted")
    conn.commit()
    conn.close()
    return images_deleted, images_recovered
Пример #4
0
def api_add_agent_image():
    if not utils.verify_digest(flask.request.data,
                               flask.request.headers["Authorization"]):
        app.logger.warning("Failed HMAC Auth")
        flask.abort(401)

    payload = flask.request.get_json()
    agent_id = payload["id"].strip()

    if utils.is_dict_empty(["id", "image"], payload):
        app.logger.warning("Mandatory fields empty")
        flask.abort(404)

    if db.get_agent(agent_id) is None:
        #TODO: replace with API error instead
        app.logger.warning("Attempted to upload picture for nonexistent agent")
        flask.abort(404)

    try:
        images.save_image(agent_id, payload["image"], images.ImageType.AGENT)
    except (KeyError, IOError):
        flask.abort(500)

    return "", 200
Пример #5
0
def act_upload(request):
    """Uploads original user image

        :param request: request from client
        :returns: uuid of uploaded image
    """
    params = request.get_json()
    username = params.get('username', None)
    file = params.get('file', None)

    uuid = save_image(file)
    if uuid is None:
        return (jsonify({'error': 'Error saving image'}), 400)

    remove_images(username)
    save_original_image_uuid(username, uuid)
    return (jsonify({'fileID': uuid}), 200)
Пример #6
0
def act_upload(request):
    """Uploads original user image

        :param request: request from client
        :returns: uuid of uploaded image
    """

    username = request.get('username', None)
    file = request.get('file', None)

    uuid = save_image(file)
    if uuid is None:
        logger.error('No image saved, uuid {0} is invalid'.format(uuid))
        return jsonify({'error': 'Error saving image'}), 400

    remove_images(username)
    save_original_image_uuid(username, uuid)
    return jsonify({'fileID': uuid}), 200
Пример #7
0
async def on_message(message):
    await bot.process_commands(message)

    if message.author.id == bot.user.id:
        return

    if is_hentai_channel(message):
        if message.attachments:
            if helpers.is_image(message.attachments[0].url):
                try:
                    saved_image = images.save_image(message.attachments[0].url)

                    if images.image_too_small(saved_image):
                        #waifu2x stuff will go here eventually
                        images.delete_image(saved_image)
                        await message.channel.send(
                            "Image too small! Gotta be bigger than 400x400 dawg."
                        )
                    else:
                        image_id = saved_image.split(".")[0]
                        try:
                            database.add_image_to_db(saved_image, message)
                            await message.channel.send(
                                'Image saved as entry #' + image_id + ". " +
                                helpers.get_random_save_message())
                        except Exception as e:
                            await message.channel.send(
                                'Image saved, but adding to database failed. Image deleted.'
                            )
                            images.delete_image(saved_image)
                            print(e)
                            await send_to_log_channel(e)
                except Exception as e:
                    await message.channel.send(
                        'Could not save image. Check the logs Zach.')
                    print(e)
                    await send_to_log_channel(e)
Пример #8
0
 def _save_image(self, img, i):
     path = self._image_path(i)
     save_image(img, path)
Пример #9
0
st = StyleTransfer(sess,
                   net,
                   ITERATIONS,
                   CONTENT_LAYERS,
                   STYLE_LAYERS,
                   content_image,
                   style_image,
                   CONTENT_LAYER_WEIGHTS,
                   STYLE_LAYER_WEIGHTS,
                   CONTENT_LOSS_WEIGHT,
                   STYLE_LOSS_WEIGHT,
                   TV_LOSS_WEIGHT,
                   OPTIMIZER,
                   learning_rate=LEARNING_RATE,
                   init_img_type=INIT_TYPE,
                   preserve_colors=PRESERVE_COLORS,
                   cvt_type=CVT_TYPE,
                   content_factor_type=CONTENT_FACTOR_TYPE,
                   save_it=SAVE_IT,
                   save_it_dir=SAVE_IT_DIR)

mixed_image = st.run()
summary = st.loss_summary()

sess.close()

save_image(mixed_image, OUTPUT_IMAGE_PATH)

with open(LOSS_SUMMARY_PATH, "wb") as handle:
    pickle.dump(summary, handle, protocol=pickle.HIGHEST_PROTOCOL)