Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better code sandbox lifecycle management #110

Merged
merged 8 commits into from
Jun 4, 2024

Conversation

humpydonkey
Copy link
Collaborator

@humpydonkey humpydonkey commented Jun 3, 2024

Motivation

Currently, chat_with_workflow() shares a global sandbox, which causes concurrency issues: parallel chat_with_workflow() execution could convolute/mess up the python runtime.

This PR changes it to creating a dedicated sandbox per chat_with_workflow() call.

Changes

  1. Better code sandbox lifecycle management;
  2. Support image visualization (model predictions) locally;
  3. Minor documentation updates;

Copy link
Member

@dillonalaird dillonalaird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for returning PIL instead of numpy? I'd generally say keep it as numpy because I think most LLMs have an easier time dealing with numpy/cv2 than PIL

@@ -523,8 +523,8 @@ def save_image(image: np.ndarray) -> str:

def overlay_bounding_boxes(
image: np.ndarray, bboxes: List[Dict[str, Any]]
) -> np.ndarray:
"""'display_bounding_boxes' is a utility function that displays bounding boxes on
) -> Image.Image:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about changing these to PIL images. Sometimes I ask it to visualize bounding boxes and then do something with that output, like mask or draw lines or whatever. While you can technically do this with PIL, I think it may be easier to do it with the numpy arrays/cv2. Need to test it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need PIL because the image needs to be visualized by the IPython display(), and display() doesn't understand numpy array.

Copy link
Collaborator Author

@humpydonkey humpydonkey Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you can technically do this with PIL, I think it may be easier to do it with the numpy arrays/cv2.

We don't have to do it with PIL. we could convert PIL to numpy array easily.
E.g. we could support both PIL and numpy array as the input image of overlay_* functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the upcoming video visualization feature, now i think it's better to run the display() function inside of every overlay_* functions because it will constraint the vizualization behavior without adding a verbose user prompt.

Then, I don't need PIL and I can change the output back to numpy array.

Copy link
Member

@dillonalaird dillonalaird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@humpydonkey humpydonkey merged commit 32e0156 into main Jun 4, 2024
7 checks passed
@humpydonkey humpydonkey deleted the minor-improvements-code-interpreter branch June 4, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants