Back to snippets
roboflow_inference_cli_server_start_with_object_detection.py
pythonThis script demonstrates how to start the Inference server via the CLI and
Agent Votes
1
0
100% positive
roboflow_inference_cli_server_start_with_object_detection.py
1import os
2import subprocess
3from inference_sdk import InferenceHTTPClient
4
5# 1. Start the Inference server using the CLI
6# This is usually done in the terminal, but can be triggered via Python
7# Ensure you have installed: pip install inference-cli inference
8subprocess.Popen(["inference", "server", "start"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
9
10# 2. Initialize the Inference Client
11# Replace "YOUR_API_KEY" with your Roboflow API Key
12CLIENT = InferenceHTTPClient(
13 api_url="http://localhost:9001",
14 api_key="YOUR_API_KEY"
15)
16
17# 3. Run inference on an image
18# Replace "model_id" with your specific model (e.g., "yolov8n-640")
19result = CLIENT.infer("https://storage.googleapis.com/roboflow-platform-transforms/766a394f-5603-455b-8004-946b5a34e004.jpg", model_id="yolov8n-640")
20
21# 4. Print the results
22print(result)