2023-12-15 20:31:28 +00:00
|
|
|
"""Command for generating image descriptions"""
|
|
|
|
|
2023-02-25 20:32:50 +00:00
|
|
|
import click
|
|
|
|
|
|
|
|
|
|
|
|
@click.argument("image_filepaths", nargs=-1)
|
|
|
|
@click.command()
|
|
|
|
def describe_cmd(image_filepaths):
|
|
|
|
"""Generate text descriptions of images."""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from imaginairy.enhancers.describe_image_blip import generate_caption
|
2023-12-10 22:46:11 +00:00
|
|
|
from imaginairy.schema import LazyLoadingImage
|
2023-02-25 20:32:50 +00:00
|
|
|
|
|
|
|
imgs = []
|
|
|
|
for p in image_filepaths:
|
|
|
|
if p.startswith("http"):
|
|
|
|
img = LazyLoadingImage(url=p)
|
|
|
|
elif os.path.isdir(p):
|
|
|
|
print(f"Skipping directory: {p}")
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
img = LazyLoadingImage(filepath=p)
|
|
|
|
imgs.append(img)
|
|
|
|
for img in imgs:
|
|
|
|
print(generate_caption(img.copy()))
|