show used images in CLI and bot; caption cmdline in bot

This commit is contained in:
Tomáš Mládek 2021-09-22 23:55:48 +02:00
parent 546102205e
commit 04ba5b7e4e
3 changed files with 30 additions and 3 deletions

View file

@ -22,6 +22,10 @@ export class ProxyImage implements CollageImage {
} }
} }
public get path(): string | null {
return this.filepath;
}
public get image(): Image { public get image(): Image {
if (!this._image) { if (!this._image) {
const image = canvasKit.MakeImageFromEncoded( const image = canvasKit.MakeImageFromEncoded(

View file

@ -94,6 +94,7 @@ if (modeKey === "recursive") {
images, images,
); );
mode.place(context, images, segments); mode.place(context, images, segments);
console.log(`Used: ${images.slice(0, segments.length).map((img) => img.path).join(", ")}`)
} }
const output = args["output"]; const output = args["output"];

View file

@ -26,7 +26,7 @@ class KollagenBot:
) -> None: ) -> None:
self.logger = logging.getLogger("kollagen") self.logger = logging.getLogger("kollagen")
self.kollagen_path = kollagen_path self.kollagen_path = kollagen_path
self.base_dir = base_dir self.base_dir = os.path.abspath(base_dir) if base_dir else None
self._init_parser() self._init_parser()
@ -174,14 +174,36 @@ class KollagenBot:
"-o", "-o",
ntf.name, ntf.name,
] ]
self.logger.debug(f"Running: " + str(shell_cmd_line)) self.logger.debug(f"Running: " + str(shell_cmd_line))
subprocess.run( result = subprocess.run(
shell_cmd_line, shell_cmd_line,
check=True, check=True,
capture_output=True, capture_output=True,
) )
ntf.seek(0) ntf.seek(0)
update.message.reply_photo(ntf)
used_line = next(
(
line
for line in result.stdout.decode("utf-8").splitlines()
if line.startswith("Used: ")
),
"",
).replace(f"{self.base_dir}/" if self.base_dir else "", "")
caption = ""
caption += (
f"`{' '.join(['/generate', *cmd_line])}`\n" if len(cmd_line) else ""
)
caption += used_line.replace("_", "\\_")
caption = caption[:200]
update.message.reply_photo(
ntf,
caption=caption,
parse_mode=ParseMode.MARKDOWN,
)
return True return True
def tg_help(self, update: Update, context: CallbackContext): def tg_help(self, update: Update, context: CallbackContext):