Skip to content

Commit 3360381

Browse files
sunildkumarbrandonbrandon-wadaAuto-format Botblaise-muhirwa
authored
Ask_async docs (#113)
* bump version * Update UNSURE to be UNCLEAR, catch __USURE received from the service (#105) * rough draft of demo * ask_async (#102) * initial commit * added ask_async to submit_image_query * Automatically reformatting code * added ask async method * Automatically reformatting code * added integration tests (requires BE merge first) * Automatically reformatting code * satisfying mypy * Automatically reformatting code * fix comments * change what type of exception test is catching * Automatically reformatting code * fix imports organization issue * fix implementation - wait must be 0 not None * Automatically reformatting code * forgot to make wait=0 in relevant test * feedback from PR review * Automatically reformatting code * ensure want_async is a serializable bool * add description * updated sphinx reqs to render some of the dependencies * updated docstring for ask_async and fixed small sphinx bugs in other folk's docstrings * Tests aren't passing because I didn't update the autogenerated code to expect a new param * Revert "Tests aren't passing because I didn't update the autogenerated code to expect a new param" This reverts commit 2477fd5. * fix generated * Automatically reformatting code * fix lint * Automatically reformatting code * Revert "Automatically reformatting code" This reverts commit cb9359e. * Revert "fix generated" This reverts commit 935c036. * Revert "Revert "Tests aren't passing because I didn't update the autogenerated code to expect a new param"" This reverts commit 07670e3. * Revert "Tests aren't passing because I didn't update the autogenerated code to expect a new param" This reverts commit 2477fd5. * Revert "updated docstring for ask_async and fixed small sphinx bugs in other folk's docstrings" This reverts commit 67e3edd. * third time at generated docs is the charm * Automatically reformatting code * finish making tests work * Automatically reformatting code --------- Co-authored-by: Auto-format Bot <[email protected]> * Cli polishing (#109) * Add basic catch if api token isn't specified when cli is called * Pushes Groundlight class instantiation up until the function is actually called with arguments. This means that the entire help args are available even if we can't instantiate the class (no api key) * Fixed misunderstanding with metaprogramming, added tests * Addressing comments --------- Co-authored-by: Auto-format Bot <[email protected]> * Add ask_confident and ask_ml (#99) * Adding ask_confident and ask_fast * Automatically reformatting code * Fixing ask_ml behavior * Adding to test * Automatically reformatting code * set default wait for ask_ml * Unhide wait functions, merging logic, fixed iq_is_answered logic * Automatically reformatting code * Rewriting doc strings in Sphinx style * ask_fast to ask_ml in the tests * fixed sphinx docstring return types * Cleaning the lint trap * Last bits of lint * Making iq submission with inspection work with newly optional patience time * single char typo * Reorder functions to trick Git's LCS alg to be correct * Automatically reformatting code --------- Co-authored-by: Auto-format Bot <[email protected]> * Linting * addressed self comments * fix ask_async docstring * small fixes * cleaning up a bit * Update docs/docs/building-applications/5-async-queries.md Co-authored-by: blaise-muhirwa <[email protected]> * Update docs/docs/building-applications/5-async-queries.md Co-authored-by: robotrapta <[email protected]> * small fixes based on PR feedback from Leo and Blaise --------- Co-authored-by: brandon <[email protected]> Co-authored-by: Brandon <[email protected]> Co-authored-by: Auto-format Bot <[email protected]> Co-authored-by: blaise-muhirwa <[email protected]> Co-authored-by: robotrapta <[email protected]>
1 parent ed7512f commit 3360381

File tree

9 files changed

+100
-8
lines changed

9 files changed

+100
-8
lines changed

docs/docs/building-applications/1-grabbing-images.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
15
# Grabbing Images
26

37
Groundlight's SDK accepts images in many popular formats, including PIL, OpenCV, and numpy arrays.

docs/docs/building-applications/working-with-detectors.md renamed to docs/docs/building-applications/2-working-with-detectors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 2
33
---
44

55
# Working with Detectors

docs/docs/building-applications/5-managing-confidence.md renamed to docs/docs/building-applications/3-managing-confidence.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
sidebar_position: 3
3+
---
14
# Confidence Levels
25

36
Groundlight gives you a simple way to control the trade-off of latency against accuracy. The longer you can wait for an answer to your image query, the better accuracy you can get. In particular, if the ML models are unsure of the best response, they will escalate the image query to more intensive analysis with more complex models and real-time human monitors as needed. Your code can easily wait for this delayed response. Either way, these new results are automatically trained into your models so your next queries will get better results faster.

docs/docs/building-applications/handling-errors.md renamed to docs/docs/building-applications/4-handling-errors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
15
# Handling Server Errors
26

37
When building applications with the Groundlight SDK, you may encounter server errors during API calls. This page covers how to handle such errors and build robust code that can gracefully handle exceptions.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# Asynchronous Queries
6+
7+
Groundlight provides a simple interface for submitting asynchronous queries. This is useful for times in which the thread or process or machine submitting image queries is not the same thread or machine that will be retrieving and using the results. For example, you might have a forward deployed robot or camera that submits image queries to Groundlight, and a separate server that retrieves the results and takes action based on them. We will refer to these two machines as the **submitting machine** and the **retrieving machine**.
8+
9+
## Setup Submitting Machine
10+
On the **submitting machine**, you will need to install the Groundlight Python SDK. Then you can submit image queries asynchronously using the `ask_async` interface (read the full documentation [here](pathname:///python-sdk/api-reference-docs/#groundlight.client.Groundlight.ask_async)). `ask_async` submits your query and returns as soon as the query is submitted. It does not wait for an answer to be available prior to returning to minimize the time your program spends interacting with Groundlight. As a result, the `ImageQuery` object `ask_async` returns lacks a `result` (the `result` field will be `None`). This is acceptable for this use case as the **submitting machine** is not interested in the result. Instead, the **submitting machine** just needs to communicate the `ImageQuery.id`s to the **retrieving machine** - this might be done via a database, a message queue, or some other mechanism. For this example, we assume you are using a database where you save the `ImageQuery.id` to it via `db.save(image_query.id)`.
11+
12+
```python notest
13+
from groundlight import Groundlight
14+
import cv2
15+
from time import sleep
16+
17+
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query")
18+
19+
cam = cv2.VideoCapture(0) # Initialize camera (0 is the default index)
20+
21+
while True:
22+
_, image = cam.read() # Capture one frame from the camera
23+
image_query = gl.ask_async(detector=detector, image=image) # Submit the frame to Groundlight
24+
db.save(image_query.id) # Save the image_query.id to a database for the retrieving machine to use
25+
sleep(10) # Sleep for 10 seconds before submitting the next query
26+
27+
cam.release() # Release the camera
28+
29+
```
30+
31+
## Setup Retrieving Machine
32+
On the **retrieving machine** you will need to install the Groundlight Python SDK. Then you can retrieve the results of the image queries submitted by another machine using `get_image_query`. The **retrieving machine** can then use the `ImageQuery.result` to take action based on the result for whatever application you are building. For this example, we assume your application looks up the next image query to process from a database via `db.get_next_image_query_id()` and that this function returns `None` once all `ImageQuery`s are processed.
33+
```python notest
34+
from groundlight import Groundlight
35+
36+
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query")
37+
38+
image_query_id = db.get_next_image_query_id()
39+
40+
while image_query_id is not None:
41+
image_query = gl.get_image_query(id=image_query_id) # retrieve the image query from Groundlight
42+
result = image_query.result
43+
44+
# take action based on the result of the image query
45+
if result.label == 'YES':
46+
pass # TODO: do something based on your application
47+
elif result.label == 'NO':
48+
pass # TODO: do something based on your application
49+
elif result.label == 'UNCLEAR':
50+
pass # TODO: do something based on your application
51+
52+
# update image_query_id for next iteration of the loop
53+
image_query_id = db.get_next_image_query_id()
54+
```
55+
56+
## Important Considerations
57+
When you submit an image query asynchronously, ML prediction on your query is **not** instant. So attempting to retrieve the result immediately after submitting an async query will likely result in an `UNCLEAR` result as Groundlight is still processing your query. Instead, if your code needs a `result` synchronously we recommend using one of our methods with a polling mechanism to retrieve the result. You can see all of the interfaces available in the documentation [here](pathname:///python-sdk/api-reference-docs/#groundlight.client.Groundlight).
58+
59+
```python notest
60+
from groundlight import Groundlight
61+
from PIL import Image
62+
63+
detector = gl.get_or_create_detector(name="your_detector_name", query="your_query")
64+
image = Image.open("/path/to/your/image.jpg")
65+
image_query = gl.ask_async(detector=detector, image=image) # Submit async query to Groundlight
66+
result = image_query.result # This will always be 'None' as you asked asynchronously
67+
68+
image_query = gl.get_image_query(id=image_query.id) # Immediately retrieve the image query from Groundlight
69+
result = image_query.result # This will likely be 'UNCLEAR' as Groundlight is still processing your query
70+
```

docs/docs/building-applications/edge.md renamed to docs/docs/building-applications/6-edge.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Using Groundlight on the edge
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Using Groundlight on the Edge
26

37
If your account has access to edge models, you can download and install them to your edge devices.
48
This allows you to run your model evaluations on the edge, reducing latency, cost, network bandwidth, and energy.

docs/docs/building-applications/industrial.md renamed to docs/docs/building-applications/7-industrial.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
15
# Industrial and Manufacturing Applications
26

37
Modern natural language-based computer vision is transforming industrial and manufacturing applications by enabling more intuitive interaction with automation systems. Groundlight offers cutting-edge computer vision technology that can be seamlessly integrated into various industrial processes, enhancing efficiency, productivity, and quality control.

docs/docs/building-applications/building-applications.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ Groundlight can be used to [apply modern natural-language-based computer vision
3737
## Further Reading
3838

3939
For more in-depth guides on various aspects of building applications with Groundlight, check out the following pages:
40-
41-
- [Working with Detectors](working-with-detectors.md): Learn how to create, configure, and use detectors in your Groundlight-powered applications.
42-
- [Using Groundlight on the edge](edge.md): Discover how to deploy Groundlight in edge computing environments for improved performance and reduced latency.
43-
- [Handling HTTP errors](handling-errors.md): Understand how to handle and troubleshoot HTTP errors that may occur while using Groundlight.
44-
40+
- **[Grabbing images](1-grabbing-images.md)**: Understand the intricacies of how to submit images from various input sources to Groundlight.
41+
- **[Working with detectors](2-working-with-detectors.md)**: Learn how to create, configure, and use detectors in your Groundlight-powered applications.
42+
- **[Confidence levels](3-managing-confidence.md)**: Master how to control the trade-off of latency against accuracy by configuring the desired confidence level for your detectors.
43+
- **[Handling server errors](4-handling-errors.md)**: Understand how to handle and troubleshoot HTTP errors that may occur while using Groundlight.
44+
- **[Asynchronous queries](5-async-queries.md)**: Groundlight makes it easy to submit asynchronous queries. Learn how to submit queries asynchronously and retrieve the results later.
45+
- **[Using Groundlight on the edge](6-edge.md)**: Discover how to deploy Groundlight in edge computing environments for improved performance and reduced latency.
46+
- **[Industrial applications](7-industrial.md)**: Learn how to apply modern natural-language-based computer vision to your industrial and manufacturing applications.
47+
4548
By exploring these resources and sample applications, you'll be well on your way to building powerful visual applications using Groundlight's computer vision and natural language capabilities.
4649

4750

docs/docs/getting-started/getting-started.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _Note: The SDK is currently in "beta" phase. Interfaces are subject to change in
1818

1919
### How does it work?
2020

21-
Your images are first analyzed by machine learning (ML) models which are automatically trained on your data. If those models have high enough [confidence](docs/building-applications/managing-confidence), that's your answer. But if the models are unsure, then the images are progressively escalated to more resource-intensive analysis methods up to real-time human review. So what you get is a computer vision system that starts working right away without even needing to first gather and label a dataset. At first it will operate with high latency, because people need to review the image queries. But over time, the ML systems will learn and improve so queries come back faster with higher confidence.
21+
Your images are first analyzed by machine learning (ML) models which are automatically trained on your data. If those models have high enough [confidence](docs/building-applications/3-managing-confidence.md), that's your answer. But if the models are unsure, then the images are progressively escalated to more resource-intensive analysis methods up to real-time human review. So what you get is a computer vision system that starts working right away without even needing to first gather and label a dataset. At first it will operate with high latency, because people need to review the image queries. But over time, the ML systems will learn and improve so queries come back faster with higher confidence.
2222

2323
### Escalation Technology
2424

0 commit comments

Comments
 (0)