Esempio n. 1
0
def import_image(barcode: str, image_url: str, ocr_url: str,
                 server_domain: str):
    logger.info("Detect insights for product {}, "
                "image {}".format(barcode, image_url))
    product_store = get_product_store()
    product = product_store[barcode]
    save_image(barcode, image_url, product, server_domain)
    launch_object_detection_job(barcode, image_url, server_domain)
    insights_all = get_insights_from_image(barcode, image_url, ocr_url)

    for insight_type, insights in insights_all.items():
        if insight_type == InsightType.image_flag:
            notify_image_flag(
                insights.insights,
                insights.source_image,  # type: ignore
                insights.barcode,
            )
            continue

        logger.info("Extracting {}".format(insight_type.name))
        importer: BaseInsightImporter = InsightImporterFactory.create(
            insight_type, product_store)

        with db.atomic():
            imported = importer.import_insights([insights],
                                                server_domain=server_domain,
                                                automatic=True)
            logger.info(
                "Import finished, {} insights imported".format(imported))
Esempio n. 2
0
def handle_image_flag_insights(insights: JSONType):
    source = insights["source"]
    barcode = insights["barcode"]
    insights_: List[JSONType] = insights["insights"]

    for insight in insights_:
        insight_subtype = insight["type"]

        if insight_subtype == "text":
            if insight["label"] == "beauty":
                moved = False
                # moved = move_to(barcode, ServerType.obf)

                if moved:
                    insight["moved"] = "obf"
                    logger.info("Product {} moved to OBF".format(barcode))

    notify_image_flag(insights_, source, barcode)
Esempio n. 3
0
def import_image(barcode: str, image_url: str, ocr_url: str):
    logger.info("Detect insights for product {}, "
                "image {}".format(barcode, image_url))
    product_store = CACHED_PRODUCT_STORE.get()
    insights_all = get_insights_from_image(barcode, image_url, ocr_url)

    if insights_all is None:
        return

    for insight_type, insights in insights_all.items():
        if insight_type == InsightType.image_flag.name:
            notify_image_flag(insights['insights'],
                              insights['source'],
                              insights['barcode'])
            continue

        logger.info("Extracting {}".format(insight_type))
        importer: InsightImporter = InsightImporterFactory.create(insight_type,
                                                                  product_store)

        with db.atomic():
            imported = importer.import_insights([insights], automatic=True)
            logger.info("Import finished, {} insights imported".format(imported))