Exemple #1
0
def send_logo_notification(logo: LogoAnnotation, probs: Dict[LogoLabelType,
                                                             float]):
    crop_url = logo.get_crop_image_url()
    prob_text = "\n".join(
        (f"{label[0]} - {label[1]}: {prob:.2g}" for label, prob in sorted(
            probs.items(), key=operator.itemgetter(1), reverse=True)))
    barcode = logo.image_prediction.image.barcode
    text = (
        f"Prediction for <{crop_url}|image> "
        f"(<https://hunger.openfoodfacts.org/logos?logo_id={logo.id}|annotate logo>, "
        f"<https://world.openfoodfacts.org/product/{barcode}|product>):\n{prob_text}"
    )
    post_message(text, settings.SLACK_OFF_ROBOTOFF_ALERT_CHANNEL)
Exemple #2
0
 def send_logo_notification(self, logo: LogoAnnotation,
                            probs: Dict[LogoLabelType, float]):
     crop_url = logo.get_crop_image_url()
     prob_text = "\n".join(
         (f"{label[0]} - {label[1]}: {prob:.2g}" for label, prob in sorted(
             probs.items(), key=operator.itemgetter(1), reverse=True)))
     barcode = logo.image_prediction.image.barcode
     base_off_url = settings.BaseURLProvider().get()
     text = (
         f"Prediction for <{crop_url}|image> "
         f"(<https://hunger.openfoodfacts.org/logos?logo_id={logo.id}|annotate logo>, "
         f"<{base_off_url}/product/{barcode}|product>):\n{prob_text}")
     self._post_message(_slack_message_block(text),
                        self.ROBOTOFF_ALERT_CHANNEL)
def test_crop_image_url(monkeypatch):
    monkeypatch.delenv("ROBOTOFF_SCHEME", raising=False)  # force defaults to apply
    logo_annotation = LogoAnnotation(
        image_prediction=ImagePrediction(
            type="label",
            model_name="test-model",
            model_version="1.0",
            image=ImageModel(
                barcode="123",
                image_id="image_id",
                source_image="/image",
                width=20,
                height=20,
            ),
        ),
        bounding_box=(1, 1, 2, 2),
    )

    assert logo_annotation.get_crop_image_url() == (
        f"https://robotoff.{settings._robotoff_domain}/api/v1/images/crop"
        + f"?image_url={settings.OFF_IMAGE_BASE_URL}/image&y_min=1&x_min=1&y_max=2&x_max=2"
    )