o
    e4                     @   sZ   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ dd Zde	de	de
fd	d
ZdS )    N)Image)CLIP_FEATURIZE_URLc                 C   sD   t | }t }|d}|j|ddd t| }|	dS )z`rf.predict` requires images formatted and base64 encoded
    @params:
        iamge_path: (str) = name reference to a given image for encoding

    returns: a base64 encoded string formatted for travel to an HTTP endpoint
    RGBZ   JPEG)qualityformatascii)
r   openioBytesIOconvertsavebase64	b64encodegetvaluedecode)
image_pathimagebuffered	image_rgbimg_str r   O/var/www/myenv/lib/python3.10/site-packages/roboflow/util/clip_compare_utils.pybase64_encode   s   


r   image1image2returnc                 C   sH   t | } t |}ddi}t| |d}tjt||d}t| d S )aT  This function base64 encodes two images and send them to the clip endpoint for
    further encoding and comparison @params

    image1: (str) = name referenceto a given image for encoding
    image2: (str) = name referenceto a given image for encoding

    returns: (float) = a value between 1 and 0, with 1 being images were identical
    zContent-Typez
text/plain)r   r   )dataheaders
similarity)r   jsondumpsrequestspostr   float)r   r   r   r   rr   r   r   clip_encode   s   	r'   )r   r   r!   r#   PILr   roboflow.configr   r   strr%   r'   r   r   r   r   <module>   s    