Giter Site home page Giter Site logo

Add order by screenshots about comfort HOT 1 CLOSED

vrslev avatar vrslev commented on June 20, 2024
Add order by screenshots

from comfort.

Comments (1)

vrslev avatar vrslev commented on June 20, 2024

There's no way to do this securely. Images from VK require authorization, so browser extension can't reach it.
In case an idea will come, keeping visual search snippet:

import base64
from typing import Any

from ikea_api.api import API
from ikea_api_wrapped import parse_item_codes


class VisualSearch(API):
    def __init__(self):
        super().__init__(
            token=None,  # type: ignore
            endpoint="https://visual-intelligence.ikea.net/visual-search/v3/public/image",
        )
        self._session.headers["X-Client-Id"] = "AIzaSyBX8RsOkAzdfM1WW0ZiHVG8q7coOdowdXk"

    def _encode_image(self, image_url: str):
        image = self._session.get(image_url).content
        return base64.b64encode(image).decode()

    def _get_response(self, image: str) -> dict[str, Any]:
        payload = {
            "jobs": [
                {
                    "base64": image,
                    "features": [
                        {
                            "type": "search",
                            "saveImage": False,
                            "includeIdentify": True,
                            "maxResults": 1,
                        }
                    ],
                }
            ]
        }
        return self._call_api(data=payload)

    def _parse_response(self, resp: dict[str, Any]):
        raw_item_code: str = resp["results"][0]["search"][0]["products"][0]["globalId"]
        return parse_item_codes(raw_item_code)[0]

    def __call__(self, image_url: str) -> Any:
        image = self._encode_image(image_url)
        resp = self._get_response(image)
        return self._parse_response(resp)


test_url = "https://www.ikea.com/ru/ru/images/products/malm-komod-s-6-yashchikami-belyy__0484884_pe621348_s5.jpg?f=xxxl"
items = VisualSearch()(test_url)
print(items)

from comfort.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.