Skip to content

Update image_edit.py#3

Open
kollarsandor wants to merge 1 commit into
inclusionAI:mainfrom
kollarsandor:patch-1
Open

Update image_edit.py#3
kollarsandor wants to merge 1 commit into
inclusionAI:mainfrom
kollarsandor:patch-1

Conversation

@kollarsandor

Copy link
Copy Markdown

No description provided.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d40f7b5bc8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/image_edit.py
Comment on lines +94 to +96
args.model_path = _normalize_path(args.model_path)
if not os.path.isdir(args.model_path):
p.error("--model_path must be an existing directory")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow remote model IDs in --model_path

The new validation rewrites --model_path to an absolute filesystem path and then requires it to exist as a local directory, which breaks the documented/standard Hugging Face usage where from_pretrained receives a repo ID like inclusionAI/LLaDA2.0-Uni. In that case this script now exits in argument parsing before loading anything, so the CLI no longer works for non-local model paths.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request significantly refactors the image editing script to improve robustness, including enhanced argument parsing, better memory management, and stricter validation of input data and model outputs. A review comment was provided suggesting a more robust implementation for handling directory paths in the output file path preparation logic to prevent potential issues when users provide directory paths.

Comment thread scripts/image_edit.py
Comment on lines +66 to +74
def _prepare_output_path(path):
path = _normalize_path(path)
root, ext = os.path.splitext(path)
if not ext or ext == ".":
path = (root if root else path) + ".png"
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
return path

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The logic for preparing the output path doesn't correctly handle directory paths. If a user provides a path ending in a separator (e.g., --output my_dir/), os.path.splitext will treat my_dir/ as the root, leading to an attempt to save a file named .png inside my_dir. This is likely not the intended behavior.

A more robust implementation would check if the provided path is a directory and append a default filename in that case.

Suggested change
def _prepare_output_path(path):
path = _normalize_path(path)
root, ext = os.path.splitext(path)
if not ext or ext == ".":
path = (root if root else path) + ".png"
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
return path
def _prepare_output_path(path):
path = _normalize_path(path)
if os.path.isdir(path) or path.endswith(os.path.sep):
path = os.path.join(path, "edited.png")
else:
root, ext = os.path.splitext(path)
if not ext or ext == ".":
path = (root if root else path) + ".png"
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
return path

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.

1 participant