Skip to content

Commit

Permalink
aider: Updated to optionally accept a different output file path.
Browse files Browse the repository at this point in the history
# Aider chat conversation:

USER: `src/invoke_training/scripts/_experimental/auto_caption/auto_caption_images.py` update this to optionally accept a different output file path

ASSISTANT: To update the script to optionally accept a different output file path, we need to:

1. Add a new argument to the argument parser for the output file path.
2. Update the `main` function to accept this new argument.
3. Use the provided output file path in the `main` function.

Here are the *SEARCH/REPLACE* blocks:

src/invoke_training/scripts/_experimental/auto_caption/auto_caption_images.py
```python
<<<<<<< SEARCH
def main(image_dir: str, prompt: str, use_cpu: bool, batch_size: int):
=======
def main(image_dir: str, prompt: str, use_cpu: bool, batch_size: int, output_path: str):
>>>>>>> REPLACE
```

src/invoke_training/scripts/_experimental/auto_caption/auto_caption_images.py
```python
<<<<<<< SEARCH
    out_path = Path("output.jsonl")
=======
    out_path = Path(output_path)
>>>>>>> REPLACE
```

src/invoke_training/scripts/_experimental/auto_caption/auto_caption_images.py
```python
<<<<<<< SEARCH
    args = parser.parse_args()
=======
    parser.add_argument(
        "--output",
        type=str,
        default="output.jsonl",
        help="(Optional) Path to the output file. Default is 'output.jsonl'.",
    )
    args = parser.parse_args()

    main(args.dir, args.prompt, args.cpu, args.batch_size, args.output)
>>>>>>> REPLACE
```
  • Loading branch information
brandonrising committed May 28, 2024
1 parent 87a41f3 commit 228696b
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def process_images(images: list[Image.Image], prompt: str, moondream, tokenizer)
return answers


def main(image_dir: str, prompt: str, use_cpu: bool, batch_size: int):
def main(image_dir: str, prompt: str, use_cpu: bool, batch_size: int, output_path: str):
device, dtype = select_device_and_dtype(use_cpu)
print(f"Using device: {device}")
print(f"Using dtype: {dtype}")

# Check that the output file does not already exist before spending time generating captions.
out_path = Path("output.jsonl")
out_path = Path(output_path)
if out_path.exists():
raise FileExistsError(f"Output file already exists: {out_path}")

Expand Down Expand Up @@ -99,6 +99,14 @@ def main(image_dir: str, prompt: str, use_cpu: bool, batch_size: int):
help="Batch size for processing images. To maximize speed, set this to the largest value that fits in GPU "
"memory.",
)
parser.add_argument(
"--output",
type=str,
default="output.jsonl",
help="(Optional) Path to the output file. Default is 'output.jsonl'.",
)
args = parser.parse_args()

main(args.dir, args.prompt, args.cpu, args.batch_size, args.output)

main(args.dir, args.prompt, args.cpu, args.batch_size)

0 comments on commit 228696b

Please sign in to comment.