
    ]jC                         d dl Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
  e j                  e j                  d      Z G d	 d
      Z G d d      Zy)    N   )AsyncClientWrapperSyncClientWrapper)RequestOptions)
Prediction   )AsyncRawPredictionsClientRawPredictionsClient.c                      e Zd ZdefdZedefd       Zdddddej                  e
   dej                  e
   d	ej                  e   dej                  e   fd
Zeeeedddej                  e   dej                  ej"                  ej$                  eej&                  f         dej                  e   dej                  e
   d	ej                  e   defdZddde
d	ej                  e   defdZddde
d	ej                  e   ddfdZeeeeddde
dej                  e   dej                  ej"                  ej$                  eej&                  f         dej                  e   dej                  e
   d	ej                  e   defdZy)PredictionsClientclient_wrapperc                &    t        |      | _        y N)r   )r
   _raw_clientselfr   s     M/root/env/lib/python3.12/site-packages/label_studio_sdk/predictions/client.py__init__zPredictionsClient.__init__   s    /~N    returnc                     | j                   S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawPredictionsClient
        r   r   s    r   with_raw_responsez#PredictionsClient.with_raw_response        r   Nprojecttaskrequest_optionsr   r   r   c                V    | j                   j                  |||      }|j                  S )a  
        List all predictions and their IDs.

        Parameters
        ----------
        project : typing.Optional[int]
            Filter predictions by project ID

        task : typing.Optional[int]
            Filter predictions by task ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[Prediction]
            Predictions list

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.predictions.list()
        r   r   listdatar   r   r   r   	_responses        r   r"   zPredictionsClient.list   s-    F $$))'Ve)f	~~r   model_versionresultscorer   r   r'   r(   r)   c                Z    | j                   j                  |||||      }|j                  S )a  
        Create a prediction for a specific task.

        Parameters
        ----------
        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Created prediction

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.predictions.create(
            model_version="yolo-v8",
            result=[
                {
                    "from_name": "bboxes",
                    "image_rotation": 0,
                    "original_height": 1080,
                    "original_width": 1920,
                    "to_name": "image",
                    "type": "rectanglelabels",
                    "value": {
                        "height": 60,
                        "rotation": 0,
                        "values": {"rectanglelabels": ["Person"]},
                        "width": 50,
                        "x": 20,
                        "y": 30,
                    },
                }
            ],
            score=0.95,
        )
        r&   r   creater#   r   r'   r(   r)   r   r   r%   s          r   r,   zPredictionsClient.createC   s8    @ $$++'e$`o , 
	 ~~r   r   idc                T    | j                   j                  ||      }|j                  S )a-  
        Get details about a specific prediction by its ID.

        Parameters
        ----------
        id : int
            Prediction ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Prediction details

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.predictions.get(
            id=1,
        )
        r.   r   getr#   r   r/   r   r%   s       r   r2   zPredictionsClient.get   s)    8 $$((_(M	~~r   c                T    | j                   j                  ||      }|j                  S )a  
        Delete a prediction by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.predictions.delete(
            id=1,
        )
        r.   r   deleter#   r3   s       r   r6   zPredictionsClient.delete   s)    6 $$++B+P	~~r   c                \    | j                   j                  ||||||      }|j                  S )a  
        Update prediction data by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Updated prediction

        Examples
        --------
        from label_studio_sdk import LabelStudio

        client = LabelStudio(
            api_key="YOUR_API_KEY",
        )
        client.predictions.update(
            id=1,
            model_version="yolo-v8",
            result=[
                {
                    "from_name": "bboxes",
                    "image_rotation": 0,
                    "original_height": 1080,
                    "original_width": 1920,
                    "to_name": "image",
                    "type": "rectanglelabels",
                    "value": {
                        "height": 60,
                        "rotation": 0,
                        "values": {"rectanglelabels": ["Person"]},
                        "width": 50,
                        "x": 20,
                        "y": 30,
                    },
                }
            ],
            score=0.95,
        )
        r&   r   updater#   r   r/   r'   r(   r)   r   r   r%   s           r   r9   zPredictionsClient.update   s:    J $$++mF%dds , 
	 ~~r   )__name__
__module____qualname__r   r   propertyr
   r   typingOptionalintr   Listr   r"   OMITstrSequenceDictAnyfloatr,   r2   r6   r9    r   r   r   r      s+   O*; O  #7     )-%);?$ %$ ooc"	$
  8$ 
Z	 $R /3QU(,%);?C s+C CO0L MN	C
 u%C ooc"C  8C 
CJ RV c v~/N Zd > UY  &//.2Q ]a D /3QU(,%);?HH s+	H
 CO0L MNH u%H ooc"H  8H 
Hr   r   c                      e Zd ZdefdZedefd       Zdddddej                  e
   dej                  e
   d	ej                  e   dej                  e   fd
Zeeeedddej                  e   dej                  ej"                  ej$                  eej&                  f         dej                  e   dej                  e
   d	ej                  e   defdZddde
d	ej                  e   defdZddde
d	ej                  e   ddfdZeeeeddde
dej                  e   dej                  ej"                  ej$                  eej&                  f         dej                  e   dej                  e
   d	ej                  e   defdZy)AsyncPredictionsClientr   c                &    t        |      | _        y r   )r	   r   r   s     r   r   zAsyncPredictionsClient.__init__  s    4NSr   r   c                     | j                   S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawPredictionsClient
        r   r   s    r   r   z(AsyncPredictionsClient.with_raw_response  r   r   Nr   r   r   r   c                r   K   | j                   j                  |||       d{   }|j                  S 7 w)a  
        List all predictions and their IDs.

        Parameters
        ----------
        project : typing.Optional[int]
            Filter predictions by project ID

        task : typing.Optional[int]
            Filter predictions by task ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[Prediction]
            Predictions list

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.predictions.list()


        asyncio.run(main())
        r   Nr!   r$   s        r   r"   zAsyncPredictionsClient.list  s:     V **//d\k/ll	~~ ms   "757r&   r'   r(   r)   c                v   K   | j                   j                  |||||       d{   }|j                  S 7 w)aF  
        Create a prediction for a specific task.

        Parameters
        ----------
        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Created prediction

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.predictions.create(
                model_version="yolo-v8",
                result=[
                    {
                        "from_name": "bboxes",
                        "image_rotation": 0,
                        "original_height": 1080,
                        "original_width": 1920,
                        "to_name": "image",
                        "type": "rectanglelabels",
                        "value": {
                            "height": 60,
                            "rotation": 0,
                            "values": {"rectanglelabels": ["Person"]},
                            "width": 50,
                            "x": 20,
                            "y": 30,
                        },
                    }
                ],
                score=0.95,
            )


        asyncio.run(main())
        r&   Nr+   r-   s          r   r,   zAsyncPredictionsClient.createM  sF     P **11'e$`o 2 
 
	 ~~
s   $979r.   r/   c                p   K   | j                   j                  ||       d{   }|j                  S 7 w)a  
        Get details about a specific prediction by its ID.

        Parameters
        ----------
        id : int
            Prediction ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Prediction details

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.predictions.get(
                id=1,
            )


        asyncio.run(main())
        r.   Nr1   r3   s       r   r2   zAsyncPredictionsClient.get  s7     H **..r?.SS	~~ T   !646c                p   K   | j                   j                  ||       d{   }|j                  S 7 w)at  
        Delete a prediction by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.predictions.delete(
                id=1,
            )


        asyncio.run(main())
        r.   Nr5   r3   s       r   r6   zAsyncPredictionsClient.delete  s7     F **11"o1VV	~~ WrQ   c                x   K   | j                   j                  ||||||       d{   }|j                  S 7 w)a  
        Update prediction data by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Prediction
            Updated prediction

        Examples
        --------
        import asyncio

        from label_studio_sdk import AsyncLabelStudio

        client = AsyncLabelStudio(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.predictions.update(
                id=1,
                model_version="yolo-v8",
                result=[
                    {
                        "from_name": "bboxes",
                        "image_rotation": 0,
                        "original_height": 1080,
                        "original_width": 1920,
                        "to_name": "image",
                        "type": "rectanglelabels",
                        "value": {
                            "height": 60,
                            "rotation": 0,
                            "values": {"rectanglelabels": ["Person"]},
                            "width": 50,
                            "x": 20,
                            "y": 30,
                        },
                    }
                ],
                score=0.95,
            )


        asyncio.run(main())
        r&   Nr8   r:   s           r   r9   zAsyncPredictionsClient.update  sH     Z **11mF%dds 2 
 
	 ~~
s   %:8:)r;   r<   r=   r   r   r>   r	   r   r?   r@   rA   r   rB   r   r"   rC   rD   rE   rF   rG   rH   r,   r2   r6   r9   rI   r   r   rK   rK     s,   T*< T  #<     )-%);?, %, ooc"	,
  8, 
Z	 ,b /3QU(,%);?K s+K CO0L MN	K
 u%K ooc"K  8K 
KZ X\ %C %V__^5T %`j %N [_ $s $8W $cg $T /3QU(,%);?PP s+	P
 CO0L MNP u%P ooc"P  8P 
Pr   rK   )r?   core.client_wrapperr   r   core.request_optionsr   types.predictionr   
raw_clientr	   r
   castrG   rC   r   rK   rI   r   r   <module>rY      sG     G 1 ) G v{{6::s# Dg gr   