diff --git a/docs/en/guides/streamlit-live-inference.md b/docs/en/guides/streamlit-live-inference.md index 65cfe090..9b27f861 100644 --- a/docs/en/guides/streamlit-live-inference.md +++ b/docs/en/guides/streamlit-live-inference.md @@ -64,24 +64,6 @@ Streamlit makes it simple to build and deploy interactive web applications. Comb This will launch the Streamlit application in your default web browser. You will see the main title, subtitle, and the sidebar with configuration options. Select your desired YOLO11 model, set the confidence and [NMS thresholds](https://www.ultralytics.com/glossary/non-maximum-suppression-nms), and click the "Start" button to begin the real-time object detection. -You can optionally supply a specific model in Python: - -!!! example "Streamlit Application with a custom model" - - === "Python" - - ```python - from ultralytics import solutions - - inf = solutions.Inference( - model="yolo11n.pt", # you can use any model that Ultralytics support, i.e. YOLO11, YOLOv10 - ) - - inf.inference() - - # Make sure to run the file using command `streamlit run path/to/file.py` - ``` - ## How It Works Under the hood, the Streamlit application uses the [Ultralytics solutions module](https://docs.ultralytics.com/reference/solutions/streamlit_inference/) to create an interactive interface. When you start the inference, the application: diff --git a/ultralytics/solutions/streamlit_inference.py b/ultralytics/solutions/streamlit_inference.py index 9da6d152..704172f1 100644 --- a/ultralytics/solutions/streamlit_inference.py +++ b/ultralytics/solutions/streamlit_inference.py @@ -160,12 +160,19 @@ class Inference: ], key=lambda x: (M_ORD.index(x[:7].lower()), T_ORD.index(x[7:].lower() or "")), ) - if self.model_path: # If user provided the custom model, insert model without suffix as *.pt is added later - available_models.insert(0, self.model_path.split(".pt", 1)[0]) + if self.model_path: # Insert user provided custom model in available_models + available_models.insert(0, self.model_path) selected_model = self.st.sidebar.selectbox("Model", available_models) with self.st.spinner("Model is downloading..."): - self.model = YOLO(f"{selected_model.lower()}.pt") # Load the YOLO model + if ( + selected_model.endswith((".pt", ".onnx", ".torchscript", ".mlpackage", ".engine")) + or "openvino_model" in selected_model + ): + model_path = selected_model + else: + model_path = f"{selected_model.lower()}.pt" # Default to .pt if no model provided during function call. + self.model = YOLO(model_path) # Load the YOLO model class_names = list(self.model.names.values()) # Convert dictionary to list of class names self.st.success("Model loaded successfully!")