> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/reference/hi/inference/inference-sdk.md).

# Inference SDK

यह `इन्फरेंस-sdk` Python पैकेज प्रदान करता है `InferenceHTTPClient`, से बात करने के लिए एक क्लाइंट [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) HTTP के माध्यम से। वही क्लाइंट Roboflow के साथ काम करता है [सर्वरलेस होस्टेड एपीआई](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api), एक [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments), एक self-hosted server, या edge device पर चलने वाले server - केवल `api_url` बदलता है।

```bash
pip install inference-sdk
```

{% hint style="info" %}
`इन्फरेंस-sdk` एक पतला HTTP क्लाइंट है और स्वयं मॉडल नहीं चलाता। अपने Python प्रक्रिया के भीतर मॉडल लोड और चलाने के लिए, का उपयोग करें [`इन्फरेंस` पैकेज](/reference/hi/inference/inference-python.md).
{% endhint %}

## त्वरित प्रारंभ

आप URLs, फ़ाइल पथों, PIL images, और NumPy arrays से images पर inference चला सकते हैं।

{% tabs %}
{% tab title="URL" %}

```python
from inference_sdk import InferenceHTTPClient
import os

image_url = "https://media.roboflow.com/inference/soccer.jpg"

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
)

results = client.infer(image_url, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}

{% tab title="NumPy Array" %}

```python
from inference_sdk import InferenceHTTPClient
import cv2
import os

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
)

numpy_image = cv2.imread("path/to/local/image.jpg")
results = client.infer(numpy_image, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}

{% tab title="PIL Image" %}

```python
from inference_sdk import InferenceHTTPClient
from PIL import Image
import os

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["API_KEY"],
)

pil_image = Image.open("path/to/local/image.jpg")
results = client.infer(pil_image, model_id="soccer-players-5fuqs/1")
print(results)
```

{% endtab %}
{% endtabs %}

एक self-hosted server के विरुद्ध पहली request पर, model weights डाउनलोड और सेट अप किए जाते हैं। आपकी network connection और model के आकार के आधार पर इस request में कुछ समय लग सकता है। एक बार model डाउनलोड हो जाने पर, subsequent requests बहुत तेज़ होती हैं। आप यह भी [models को pre-load कर सकते हैं और loaded weights को प्रबंधित कर सकते हैं](/reference/hi/inference/inference-sdk/model-management.md) इस प्रक्रिया को नियंत्रित करने के लिए।

{% hint style="info" %}
मॉडल ID इस स्ट्रिंग से बनती है `<project_id>/<version_id>`. देखें [Workspace और Project IDs](/reference/hi/authentication/authentication/workspace-and-project-ids.md) अपना वाला खोजने के लिए।
{% endhint %}

### Self-hosted server

आप Inference Server को self-host भी कर सकते हैं (देखें [Inference CLI](/reference/hi/inference/inference-cli.md)), और फिर बदलें `api_url` में `InferenceHTTPClient`:

```python
client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key=os.environ["API_KEY"],
)
```

### AsyncIO client

```python
import asyncio
from inference_sdk import InferenceHTTPClient

CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"
loop = asyncio.get_event_loop()
result = loop.run_until_complete(
  CLIENT.infer_async(image_url, model_id="soccer-players-5fuqs/1")
)
```

## समानांतर और बैच inference

आप एक ही call में कई images के विरुद्ध predict करना चाह सकते हैं। के दो parameters [`InferenceConfiguration`](/reference/hi/inference/inference-sdk/configuration.md) batching और parallelism को नियंत्रित करते हैं:

* `max_concurrent_requests` - शुरू किए जा सकने वाले concurrent requests की अधिकतम संख्या
* `max_batch_size` - एक single request में inject किए जा सकने वाले elements की अधिकतम संख्या

इससे निम्न सुधार संभव होते हैं:

* यदि आप inference container को एक शक्तिशाली on-prem GPU मशीन पर चलाते हैं, तो setting `max_batch_size` को सही ढंग से सेट करने से throughput लाभ मिल सकते हैं
* यदि आप hosted Roboflow API के विरुद्ध inference चलाते हैं, तो setting `max_concurrent_requests` के कारण कई images एक साथ served होती हैं, जिससे throughput लाभ मिलता है
* दोनों विकल्पों का संयोजन उन clients के लिए लाभकारी हो सकता है जो inference container को machines के cluster पर चला रहे हैं: एक single node का load अनुकूलित किया जा सकता है और अलग-अलग nodes पर parallel requests एक समय में की जा सकती हैं

```python
from inference_sdk import InferenceHTTPClient

image_url = "https://source.roboflow.com/pwYAXv9BTpqLyFfgQoPZ/u48G0UpWfk8giSw7wrU8/original.jpg"

# ROBOFLOW_API_KEY को अपने Roboflow API Key से बदलें
CLIENT = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key="ROBOFLOW_API_KEY"
)
predictions = CLIENT.infer([image_url] * 5, model_id="soccer-players-5fuqs/1")

print(predictions)
```

जिन Methods में batching और parallelism का समर्थन है:

* `infer(...)` और `infer_async(...)`
* `ocr_image(...)` और `ocr_image_async(...)` (यह लागू करते हुए `max_batch_size=1`)
* `detect_gazes(...)` और `detect_gazes_async(...)` - **अप्रचलित**, हमेशा फेंकता है `inference_sdk.http.errors.FeatureDeprecatedError`
* `get_clip_image_embeddings(...)` और `get_clip_image_embeddings_async(...)`

क्लाइंट यह भी समर्थन करता है [मुख्य फाउंडेशन मॉडल](/reference/hi/inference/inference-sdk/core-models.md) (CLIP, DocTR), [Workflows चलाना](/reference/hi/inference/inference-sdk/workflows.md) बहु-चरणीय pipelines के लिए, और [WebRTC streaming](/reference/hi/inference/inference-sdk/webrtc.md) वास्तविक-समय video inference के लिए। Webcams, camera streams, और video files को किसी model या Workflow के साथ संसाधित करने के लिए WebRTC का उपयोग करें।

## वास्तव में prediction के रूप में क्या लौटाया जाता है?

`InferenceHTTPClient` साधारण Python dictionaries लौटाता है जो model serving API से आने वाले responses होते हैं। संशोधन केवल के संदर्भ में किया जाता है `visualization` key, जो server द्वारा उत्पन्न prediction visualisation को बनाए रखता है और इसे मनचाहे format में transcode किया जा सकता है। client-side rescaling केवल input size समायोजित करता है।

## अगले चरण

* [Configuration](/reference/hi/inference/inference-sdk/configuration.md) - client और model parameters, context managers, और defaults.
* [Model Management](/reference/hi/inference/inference-sdk/model-management.md) - server पर models को pre-load, सूचीबद्ध, और unload करें.
* [Core Models](/reference/hi/inference/inference-sdk/core-models.md) - CLIP और DocTR endpoints.
* [वर्कफ़्लोज़](/reference/hi/inference/inference-sdk/workflows.md) - client के माध्यम से एक Workflow चलाएँ.
* [WebRTC Streaming](/reference/hi/inference/inference-sdk/webrtc.md) - किसी model या Workflow के माध्यम से video stream करें.
