diff --git a/docs/en/datasets/explorer/dashboard.md b/docs/en/datasets/explorer/dashboard.md index acb99cc2a0e..4df3fea414c 100644 --- a/docs/en/datasets/explorer/dashboard.md +++ b/docs/en/datasets/explorer/dashboard.md @@ -6,7 +6,7 @@ keywords: Ultralytics, Explorer GUI, semantic search, vector similarity search, # Explorer GUI -Explorer GUI is like a playground build using (Ultralytics Explorer API)[api.md]. It allows you to run semantic/vector similarity search, SQL queries and even search using natural language using our ask AI feature powered by LLMs. +Explorer GUI is like a playground build using [Ultralytics Explorer API](api.md). It allows you to run semantic/vector similarity search, SQL queries and even search using natural language using our ask AI feature powered by LLMs. ### Installation diff --git a/docs/en/datasets/explorer/index.md b/docs/en/datasets/explorer/index.md index 0f94982a11b..162744ff329 100644 --- a/docs/en/datasets/explorer/index.md +++ b/docs/en/datasets/explorer/index.md @@ -6,7 +6,13 @@ keywords: Ultralytics Explorer, CV Dataset Tools, Semantic Search, SQL Dataset Q # Ultralytics Explorer -Ultralytics Explorer is a tool for exploring CV datasets using semantic search, SQL queries and vector similarity search. It is also a Python API for accessing the same functionality. +
+
+
-
-
+
+
diff --git a/docs/en/reference/cfg/__init__.md b/docs/en/reference/cfg/__init__.md
index d73a9f2b85f..b8db12c5d04 100644
--- a/docs/en/reference/cfg/__init__.md
+++ b/docs/en/reference/cfg/__init__.md
@@ -43,6 +43,10 @@ keywords: Ultralytics, YOLO, Configuration, cfg2dict, handle_deprecation, merge_
+## ::: ultralytics.cfg.handle_explorer
+
+
+
## ::: ultralytics.cfg.parse_key_value_pair
diff --git a/docs/en/reference/solutions/distance_calculation.md b/docs/en/reference/solutions/distance_calculation.md
index 5376a2d1bdb..436188563cc 100644
--- a/docs/en/reference/solutions/distance_calculation.md
+++ b/docs/en/reference/solutions/distance_calculation.md
@@ -7,7 +7,7 @@ keywords: Ultralytics, YOLO, distance calculation, object tracking, data visuali
!!! Note
- This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/distance_calculation.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/distance_calculation.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/solutions/heatmap.py) ๐ ๏ธ. Thank you ๐!
+ This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/distance_calculation.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/distance_calculation.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/solutions/distance_calculation.py) ๐ ๏ธ. Thank you ๐!
diff --git a/docs/en/reference/solutions/speed_estimation.md b/docs/en/reference/solutions/speed_estimation.md
index 86d29b1d0ac..93cc87e6127 100644
--- a/docs/en/reference/solutions/speed_estimation.md
+++ b/docs/en/reference/solutions/speed_estimation.md
@@ -7,7 +7,7 @@ keywords: Ultralytics YOLO, speed estimation software, real-time vehicle trackin
!!! Note
- This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/speed_estimation.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/speed_estimation.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/solutions/object_counter.py) ๐ ๏ธ. Thank you ๐!
+ This file is available at [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/speed_estimation.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/speed_estimation.py). If you spot a problem please help fix it by [contributing](https://docs.ultralytics.com/help/contributing/) a [Pull Request](https://github.com/ultralytics/ultralytics/edit/main/ultralytics/solutions/speed_estimation.py) ๐ ๏ธ. Thank you ๐!
diff --git a/docs/en/usage/python.md b/docs/en/usage/python.md
index 9521b2ae51c..5577bbac736 100644
--- a/docs/en/usage/python.md
+++ b/docs/en/usage/python.md
@@ -240,6 +240,53 @@ Benchmark mode is used to profile the speed and accuracy of various export forma
[Benchmark Examples](../modes/benchmark.md){ .md-button }
+## Explorer
+
+Explorer API can be used to explore datasets with advanced semantic, vector-similarity and SQL search among other features. It also searching for images based on their content using natural language by utilizing the power of LLMs. The Explorer API allows you to write your own dataset exploration notebooks or scripts to get insights into your datasets.
+
+!!! Example "Semantic Search Using Explorer"
+
+ === "Using Images"
+
+ ```python
+ from ultralytics import Explorer
+
+ # create an Explorer object
+ exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
+ exp.create_embeddings_table()
+
+ similar = exp.get_similar(img='https://ultralytics.com/images/bus.jpg', limit=10)
+ print(similar.head())
+
+ # Search using multiple indices
+ similar = exp.get_similar(
+ img=['https://ultralytics.com/images/bus.jpg',
+ 'https://ultralytics.com/images/bus.jpg'],
+ limit=10
+ )
+ print(similar.head())
+ ```
+
+ === "Using Dataset Indices"
+
+ ```python
+ from ultralytics import Explorer
+
+ # create an Explorer object
+ exp = Explorer(data='coco128.yaml', model='yolov8n.pt')
+ exp.create_embeddings_table()
+
+ similar = exp.get_similar(idx=1, limit=10)
+ print(similar.head())
+
+ # Search using multiple indices
+ similar = exp.get_similar(idx=[1,10], limit=10)
+ print(similar.head())
+ ```
+
+[Explorer](../datasets/explorer/index.md){ .md-button }
+
+
## Using Trainers
`YOLO` model class is a high-level wrapper on the Trainer classes. Each YOLO task has its own trainer that inherits from `BaseTrainer`.
diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml
index a27cab178cb..64e2af64d72 100644
--- a/docs/mkdocs.yml
+++ b/docs/mkdocs.yml
@@ -170,12 +170,14 @@ nav:
- Classify: tasks/classify.md
- Pose: tasks/pose.md
- OBB: tasks/obb.md
- - Guides:
- - guides/index.md
- Models:
- models/index.md
- Datasets:
- datasets/index.md
+ - Guides:
+ - guides/index.md
+ - NEW ๐ Explorer:
+ - datasets/explorer/index.md
- Languages:
- ๐ฌ๐ง  English: https://docs.ultralytics.com/
- ๐จ๐ณ  ็ฎไฝไธญๆ: https://docs.ultralytics.com/zh/
@@ -188,7 +190,14 @@ nav:
- ๐ต๐น  Portuguรชs: https://docs.ultralytics.com/pt/
- ๐ฎ๐ณ  เคนเคฟเคจเฅเคฆเฅ: https://docs.ultralytics.com/hi/
- ๐ธ๐ฆ  ุงูุนุฑุจูุฉ: https://docs.ultralytics.com/ar/
- - Quickstart: quickstart.md
+ - Quickstart:
+ - quickstart.md
+ - Usage:
+ - CLI: usage/cli.md
+ - Python: usage/python.md
+ - Callbacks: usage/callbacks.md
+ - Configuration: usage/cfg.md
+ - Advanced Customization: usage/engine.md
- Modes:
- modes/index.md
- Train: modes/train.md
@@ -219,7 +228,7 @@ nav:
- RT-DETR (Realtime Detection Transformer): models/rtdetr.md
- Datasets:
- datasets/index.md
- - Explorer:
+ - NEW ๐ Explorer:
- datasets/explorer/index.md
- Explorer API: datasets/explorer/api.md
- Explorer Dashboard: datasets/explorer/dashboard.md
@@ -263,6 +272,11 @@ nav:
- DOTA8: datasets/obb/dota8.md
- Multi-Object Tracking:
- datasets/track/index.md
+ - NEW ๐ Explorer:
+ - datasets/explorer/index.md
+ - Explorer API: datasets/explorer/api.md
+ - Explorer Dashboard Demo: datasets/explorer/dashboard.md
+ - VOC Exploration Example: datasets/explorer/explorer.ipynb
- Guides:
- guides/index.md
- YOLO Common Issues: guides/yolo-common-issues.md
@@ -290,6 +304,31 @@ nav:
- VisionEye Mapping: guides/vision-eye.md
- Speed Estimation: guides/speed-estimation.md
- Distance Calculation: guides/distance-calculation.md
+ - YOLOv5:
+ - yolov5/index.md
+ - Quickstart: yolov5/quickstart_tutorial.md
+ - Environments:
+ - Amazon Web Services (AWS): yolov5/environments/aws_quickstart_tutorial.md
+ - Google Cloud (GCP): yolov5/environments/google_cloud_quickstart_tutorial.md
+ - AzureML: yolov5/environments/azureml_quickstart_tutorial.md
+ - Docker Image: yolov5/environments/docker_image_quickstart_tutorial.md
+ - Tutorials:
+ - Train Custom Data: yolov5/tutorials/train_custom_data.md
+ - Tips for Best Training Results: yolov5/tutorials/tips_for_best_training_results.md
+ - Multi-GPU Training: yolov5/tutorials/multi_gpu_training.md
+ - PyTorch Hub: yolov5/tutorials/pytorch_hub_model_loading.md
+ - TFLite, ONNX, CoreML, TensorRT Export: yolov5/tutorials/model_export.md
+ - NVIDIA Jetson Nano Deployment: yolov5/tutorials/running_on_jetson_nano.md
+ - Test-Time Augmentation (TTA): yolov5/tutorials/test_time_augmentation.md
+ - Model Ensembling: yolov5/tutorials/model_ensembling.md
+ - Pruning/Sparsity Tutorial: yolov5/tutorials/model_pruning_and_sparsity.md
+ - Hyperparameter evolution: yolov5/tutorials/hyperparameter_evolution.md
+ - Transfer learning with frozen layers: yolov5/tutorials/transfer_learning_with_frozen_layers.md
+ - Architecture Summary: yolov5/tutorials/architecture_description.md
+ - Roboflow Datasets: yolov5/tutorials/roboflow_datasets_integration.md
+ - Neural Magic's DeepSparse: yolov5/tutorials/neural_magic_pruning_quantization.md
+ - Comet Logging: yolov5/tutorials/comet_logging_integration.md
+ - Clearml Logging: yolov5/tutorials/clearml_logging_integration.md
- Integrations:
- integrations/index.md
- Comet ML: integrations/comet.md
@@ -303,37 +342,6 @@ nav:
- Neural Magic: integrations/neural-magic.md
- TensorBoard: integrations/tensorboard.md
- Amazon SageMaker: integrations/amazon-sagemaker.md
- - Usage:
- - CLI: usage/cli.md
- - Python: usage/python.md
- - Callbacks: usage/callbacks.md
- - Configuration: usage/cfg.md
- - Advanced Customization: usage/engine.md
- - YOLOv5:
- - yolov5/index.md
- - Quickstart: yolov5/quickstart_tutorial.md
- - Environments:
- - Amazon Web Services (AWS): yolov5/environments/aws_quickstart_tutorial.md
- - Google Cloud (GCP): yolov5/environments/google_cloud_quickstart_tutorial.md
- - AzureML: yolov5/environments/azureml_quickstart_tutorial.md
- - Docker Image: yolov5/environments/docker_image_quickstart_tutorial.md
- - Tutorials:
- - Train Custom Data: yolov5/tutorials/train_custom_data.md
- - Tips for Best Training Results: yolov5/tutorials/tips_for_best_training_results.md
- - Multi-GPU Training: yolov5/tutorials/multi_gpu_training.md
- - PyTorch Hub: yolov5/tutorials/pytorch_hub_model_loading.md
- - TFLite, ONNX, CoreML, TensorRT Export: yolov5/tutorials/model_export.md
- - NVIDIA Jetson Nano Deployment: yolov5/tutorials/running_on_jetson_nano.md
- - Test-Time Augmentation (TTA): yolov5/tutorials/test_time_augmentation.md
- - Model Ensembling: yolov5/tutorials/model_ensembling.md
- - Pruning/Sparsity Tutorial: yolov5/tutorials/model_pruning_and_sparsity.md
- - Hyperparameter evolution: yolov5/tutorials/hyperparameter_evolution.md
- - Transfer learning with frozen layers: yolov5/tutorials/transfer_learning_with_frozen_layers.md
- - Architecture Summary: yolov5/tutorials/architecture_description.md
- - Roboflow Datasets: yolov5/tutorials/roboflow_datasets_integration.md
- - Neural Magic's DeepSparse: yolov5/tutorials/neural_magic_pruning_quantization.md
- - Comet Logging: yolov5/tutorials/comet_logging_integration.md
- - Clearml Logging: yolov5/tutorials/clearml_logging_integration.md
- HUB:
- hub/index.md
- Quickstart: hub/quickstart.md
@@ -357,6 +365,11 @@ nav:
- build: reference/data/build.md
- converter: reference/data/converter.md
- dataset: reference/data/dataset.md
+ - explorer:
+ - explorer: reference/data/explorer/explorer.md
+ - gui:
+ - dash: reference/data/explorer/gui/dash.md
+ - utils: reference/data/explorer/utils.md
- loaders: reference/data/loaders.md
- split_dota: reference/data/split_dota.md
- utils: reference/data/utils.md
@@ -436,10 +449,10 @@ nav:
- tasks: reference/nn/tasks.md
- solutions:
- ai_gym: reference/solutions/ai_gym.md
+ - distance_calculation: reference/solutions/distance_calculation.md
- heatmap: reference/solutions/heatmap.md
- object_counter: reference/solutions/object_counter.md
- speed_estimation: reference/solutions/speed_estimation.md
- - distance_calculation: reference/solutions/distance_calculation.md
- trackers:
- basetrack: reference/trackers/basetrack.md
- bot_sort: reference/trackers/bot_sort.md
diff --git a/tests/test_explorer.py b/tests/test_explorer.py
index ce44d75cc85..23121c43c05 100644
--- a/tests/test_explorer.py
+++ b/tests/test_explorer.py
@@ -1,8 +1,11 @@
+import PIL
+
from ultralytics import Explorer
from ultralytics.utils import ASSETS
def test_similarity():
+ """Test similarity calculations and SQL queries for correctness and response length."""
exp = Explorer()
exp.create_embeddings_table()
similar = exp.get_similar(idx=1)
@@ -18,6 +21,7 @@ def test_similarity():
def test_det():
+ """Test detection functionalities and ensure the embedding table has bounding boxes."""
exp = Explorer(data='coco8.yaml', model='yolov8n.pt')
exp.create_embeddings_table(force=True)
assert len(exp.table.head()['bboxes']) > 0
@@ -25,27 +29,26 @@ def test_det():
assert len(similar) > 0
# This is a loose test, just checks errors not correctness
similar = exp.plot_similar(idx=[1, 2], limit=10)
- assert similar is not None
- similar.show()
+ assert isinstance(similar, PIL.Image.Image)
def test_seg():
+ """Test segmentation functionalities and verify the embedding table includes masks."""
exp = Explorer(data='coco8-seg.yaml', model='yolov8n-seg.pt')
exp.create_embeddings_table(force=True)
assert len(exp.table.head()['masks']) > 0
similar = exp.get_similar(idx=[1, 2], limit=10)
assert len(similar) > 0
similar = exp.plot_similar(idx=[1, 2], limit=10)
- assert similar is not None
- similar.show()
+ assert isinstance(similar, PIL.Image.Image)
def test_pose():
+ """Test pose estimation functionalities and check the embedding table for keypoints."""
exp = Explorer(data='coco8-pose.yaml', model='yolov8n-pose.pt')
exp.create_embeddings_table(force=True)
assert len(exp.table.head()['keypoints']) > 0
similar = exp.get_similar(idx=[1, 2], limit=10)
assert len(similar) > 0
similar = exp.plot_similar(idx=[1, 2], limit=10)
- assert similar is not None
- similar.show()
+ assert isinstance(similar, PIL.Image.Image)
diff --git a/ultralytics/data/explorer/__init__.py b/ultralytics/data/explorer/__init__.py
index e4af304f945..f0344e2da43 100644
--- a/ultralytics/data/explorer/__init__.py
+++ b/ultralytics/data/explorer/__init__.py
@@ -1,3 +1,5 @@
+# Ultralytics YOLO ๐, AGPL-3.0 license
+
from .utils import plot_query_result
__all__ = ['plot_query_result']
diff --git a/ultralytics/data/explorer/explorer.py b/ultralytics/data/explorer/explorer.py
index 064697e0214..4a8595d6aea 100644
--- a/ultralytics/data/explorer/explorer.py
+++ b/ultralytics/data/explorer/explorer.py
@@ -1,3 +1,5 @@
+# Ultralytics YOLO ๐, AGPL-3.0 license
+
from io import BytesIO
from pathlib import Path
from typing import Any, List, Tuple, Union
@@ -24,9 +26,8 @@ class ExplorerDataset(YOLODataset):
def __init__(self, *args, data: dict = None, **kwargs) -> None:
super().__init__(*args, data=data, **kwargs)
- # NOTE: Load the image directly without any resize operations.
def load_image(self, i: int) -> Union[Tuple[np.ndarray, Tuple[int, int], Tuple[int, int]], Tuple[None, None, None]]:
- """Loads 1 image from dataset index 'i', returns (im, resized hw)."""
+ """Loads 1 image from dataset index 'i' without any resize ops."""
im, f, fn = self.ims[i], self.im_files[i], self.npy_files[i]
if im is None: # not cached in RAM
if fn.exists(): # load npy
@@ -41,6 +42,7 @@ def load_image(self, i: int) -> Union[Tuple[np.ndarray, Tuple[int, int], Tuple[i
return self.ims[i], self.im_hw0[i], self.im_hw[i]
def build_transforms(self, hyp: IterableSimpleNamespace = None):
+ """Creates transforms for dataset images without resizing."""
return Format(
bbox_format='xyxy',
normalize=False,
@@ -122,7 +124,7 @@ def create_embeddings_table(self, force: bool = False, split: str = 'train') ->
self.table = table
def _yield_batches(self, dataset: ExplorerDataset, data_info: dict, model: YOLO, exclude_keys: List[str]):
- # Implement Batching
+ """Generates batches of data for embedding, excluding specified keys."""
for i in tqdm(range(len(dataset))):
self.progress = float(i + 1) / len(dataset)
batch = dataset[i]
@@ -143,7 +145,7 @@ def query(self,
limit (int): Number of results to return.
Returns:
- An arrow table containing the results. Supports converting to:
+ (pyarrow.Table): An arrow table containing the results. Supports converting to:
- pandas dataframe: `result.to_pandas()`
- dict of lists: `result.to_pydict()`
@@ -175,7 +177,7 @@ def sql_query(self,
return_type (str): Type of the result to return. Can be either 'pandas' or 'arrow'. Defaults to 'pandas'.
Returns:
- An arrow table containing the results.
+ (pyarrow.Table): An arrow table containing the results.
Example:
```python
@@ -216,7 +218,7 @@ def plot_sql_query(self, query: str, labels: bool = True) -> Image.Image:
labels (bool): Whether to plot the labels or not.
Returns:
- PIL Image containing the plot.
+ (PIL.Image): Image containing the plot.
Example:
```python
@@ -248,7 +250,7 @@ def get_similar(self,
return_type (str): Type of the result to return. Can be either 'pandas' or 'arrow'. Defaults to 'pandas'.
Returns:
- A table or pandas dataframe containing the results.
+ (pandas.DataFrame): A dataframe containing the results.
Example:
```python
@@ -282,7 +284,7 @@ def plot_similar(self,
limit (int): Number of results to return. Defaults to 25.
Returns:
- PIL Image containing the plot.
+ (PIL.Image): Image containing the plot.
Example:
```python
@@ -306,11 +308,12 @@ def similarity_index(self, max_dist: float = 0.2, top_k: float = None, force: bo
Args:
max_dist (float): maximum L2 distance between the embeddings to consider. Defaults to 0.2.
top_k (float): Percentage of the closest data points to consider when counting. Used to apply limit when running
- vector search. Defaults: None.
+ vector search. Defaults: None.
force (bool): Whether to overwrite the existing similarity index or not. Defaults to True.
Returns:
- A pandas dataframe containing the similarity index.
+ (pandas.DataFrame): A dataframe containing the similarity index. Each row corresponds to an image, and columns
+ include indices of similar images and their respective distances.
Example:
```python
@@ -340,6 +343,7 @@ def similarity_index(self, max_dist: float = 0.2, top_k: float = None, force: bo
sim_table = self.connection.create_table(sim_idx_table_name, schema=get_sim_index_schema(), mode='overwrite')
def _yield_sim_idx():
+ """Generates a dataframe with similarity indices and distances for images."""
for i in tqdm(range(len(embeddings))):
sim_idx = self.table.search(embeddings[i]).limit(top_k).to_pandas().query(f'_distance <= {max_dist}')
yield [{
@@ -364,7 +368,7 @@ def plot_similarity_index(self, max_dist: float = 0.2, top_k: float = None, forc
force (bool): Whether to overwrite the existing similarity index or not. Defaults to True.
Returns:
- PIL.PngImagePlugin.PngImageFile containing the plot.
+ (PIL.Image): Image containing the plot.
Example:
```python
@@ -416,7 +420,7 @@ def ask_ai(self, query):
query (str): Question to ask.
Returns:
- Answer from AI.
+ (pandas.DataFrame): A dataframe containing filtered results to the SQL query.
Example:
```python
@@ -436,14 +440,17 @@ def ask_ai(self, query):
def visualize(self, result):
"""
- Visualize the results of a query.
+ Visualize the results of a query. TODO.
Args:
- result (arrow table): Arrow table containing the results of a query.
+ result (pyarrow.Table): Table containing the results of a query.
"""
- # TODO:
pass
def generate_report(self, result):
- """Generate a report of the dataset."""
+ """
+ Generate a report of the dataset.
+
+ TODO
+ """
pass
diff --git a/ultralytics/data/explorer/gui/__init__.py b/ultralytics/data/explorer/gui/__init__.py
index e69de29bb2d..9e68dc12245 100644
--- a/ultralytics/data/explorer/gui/__init__.py
+++ b/ultralytics/data/explorer/gui/__init__.py
@@ -0,0 +1 @@
+# Ultralytics YOLO ๐, AGPL-3.0 license
diff --git a/ultralytics/data/explorer/gui/dash.py b/ultralytics/data/explorer/gui/dash.py
index e9e7ac2ade0..d2b5ec21432 100644
--- a/ultralytics/data/explorer/gui/dash.py
+++ b/ultralytics/data/explorer/gui/dash.py
@@ -1,3 +1,5 @@
+# Ultralytics YOLO ๐, AGPL-3.0 license
+
import time
from threading import Thread
@@ -7,13 +9,13 @@
from ultralytics.utils import ROOT, SETTINGS
from ultralytics.utils.checks import check_requirements
-check_requirements('streamlit>=1.29.0')
-check_requirements('streamlit-select>=0.2')
+check_requirements(('streamlit>=1.29.0', 'streamlit-select>=0.2'))
import streamlit as st
from streamlit_select import image_select
def _get_explorer():
+ """Initializes and returns an instance of the Explorer class."""
exp = Explorer(data=st.session_state.get('dataset'), model=st.session_state.get('model'))
thread = Thread(target=exp.create_embeddings_table,
kwargs={'force': st.session_state.get('force_recreate_embeddings')})
@@ -28,6 +30,7 @@ def _get_explorer():
def init_explorer_form():
+ """Initializes an Explorer instance and creates embeddings table with progress tracking."""
datasets = ROOT / 'cfg' / 'datasets'
ds = [d.name for d in datasets.glob('*.yaml')]
models = [
@@ -46,6 +49,7 @@ def init_explorer_form():
def query_form():
+ """Sets up a form in Streamlit to initialize Explorer with dataset and model selection."""
with st.form('query_form'):
col1, col2 = st.columns([0.8, 0.2])
with col1:
@@ -58,6 +62,7 @@ def query_form():
def ai_query_form():
+ """Sets up a Streamlit form for user input to initialize Explorer with dataset and model selection."""
with st.form('ai_query_form'):
col1, col2 = st.columns([0.8, 0.2])
with col1:
@@ -67,6 +72,7 @@ def ai_query_form():
def find_similar_imgs(imgs):
+ """Initializes a Streamlit form for AI-based image querying with custom input."""
exp = st.session_state['explorer']
similar = exp.get_similar(img=imgs, limit=st.session_state.get('limit'), return_type='arrow')
paths = similar.to_pydict()['im_file']
@@ -74,6 +80,7 @@ def find_similar_imgs(imgs):
def similarity_form(selected_imgs):
+ """Initializes a form for AI-based image querying with custom input in Streamlit."""
st.write('Similarity Search')
with st.form('similarity_form'):
subcol1, subcol2 = st.columns([1, 1])
@@ -109,6 +116,7 @@ def similarity_form(selected_imgs):
def run_sql_query():
+ """Executes an SQL query and returns the results."""
st.session_state['error'] = None
query = st.session_state.get('query')
if query.rstrip().lstrip():
@@ -118,6 +126,7 @@ def run_sql_query():
def run_ai_query():
+ """Execute SQL query and update session state with query results."""
if not SETTINGS['openai_api_key']:
st.session_state[
'error'] = 'OpenAI API key not found in settings. Please run yolo settings openai_api_key="..."'
@@ -134,12 +143,14 @@ def run_ai_query():
def reset_explorer():
+ """Resets the explorer to its initial state by clearing session variables."""
st.session_state['explorer'] = None
st.session_state['imgs'] = None
st.session_state['error'] = None
def utralytics_explorer_docs_callback():
+ """Resets the explorer to its initial state by clearing session variables."""
with st.container(border=True):
st.image('https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg',
width=100)
@@ -151,6 +162,7 @@ def utralytics_explorer_docs_callback():
def layout():
+ """Resets explorer session variables and provides documentation with a link to API docs."""
st.set_page_config(layout='wide', initial_sidebar_state='collapsed')
st.markdown("