From 12f5a435ee6476e2e07ded0c9cdd597c70ca8af0 Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 13 Jan 2025 22:26:35 -0500 Subject: changing ai for images and collections to work mostly the same way. fixes for document view/collection/images to keep things working when the ai editor view reduces the rendered document size. fixed so that freeform views overlaid on images/vieos/etc have the ui menu items of collections. --- src/client/views/smartdraw/DrawingFillHandler.tsx | 17 ++++++++--------- src/client/views/smartdraw/SmartDrawHandler.tsx | 8 ++++---- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src/client/views/smartdraw') diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx index 423e3b2ac..d9a01c436 100644 --- a/src/client/views/smartdraw/DrawingFillHandler.tsx +++ b/src/client/views/smartdraw/DrawingFillHandler.tsx @@ -15,7 +15,7 @@ export class DrawingFillHandler { const docData = drawing[DocData]; const tags: string[] = ((docData?.tags as unknown as string[]) ?? []).map(tag => tag.slice(1)) ?? []; const styles = tags.filter(tag => FireflyStylePresets.has(tag)); - DocumentView.GetDocImage(drawing)?.then(imageField => { + return DocumentView.GetDocImage(drawing)?.then(imageField => { if (imageField) { const aspectRatio = (drawing.width as number) / (drawing.height as number); let dims: { width: number; height: number }; @@ -31,18 +31,17 @@ export class DrawingFillHandler { const { href } = ImageCast(imageField).url; const hrefParts = href.split('.'); const structureUrl = `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`; - imageUrlToBase64(structureUrl) - .then((hrefBase64: string) => gptDescribeImage(hrefBase64)) - .then(prompt => { + return imageUrlToBase64(structureUrl) + .then(gptDescribeImage) + .then(prompt => Networking.PostToServer('/queryFireflyImageFromStructure', - { prompt: `${user_prompt}, ${prompt}`, width: dims.width, height: dims.height, structureUrl, strength, styles }) + { prompt: `${user_prompt || prompt}`, width: dims.width, height: dims.height, structureUrl, strength, styles }) .then((info: Upload.ImageInformation) => DocumentViewInternal.addDocTabFunc(Docs.Create.ImageDocument(info.accessPaths.agnostic.client, - { ai: 'firefly', ai_firefly_prompt: user_prompt || prompt, _width: 500, data_nativeWidth: info.nativeWidth, data_nativeHeight: info.nativeHeight }), OpenWhere.addRight) - ).catch(e => alert("create image failed: " + e.toString())); // prettier-ignore - }); + { ai: 'firefly', title: user_prompt || prompt, ai_firefly_prompt: user_prompt || prompt, _width: 500, data_nativeWidth: info.nativeWidth, data_nativeHeight: info.nativeHeight }), OpenWhere.addRight) + ).catch(e => alert("create image failed: " + e.toString())) + ); // prettier-ignore } - return false; }); }; } diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx index f635b5642..7db9ef133 100644 --- a/src/client/views/smartdraw/SmartDrawHandler.tsx +++ b/src/client/views/smartdraw/SmartDrawHandler.tsx @@ -271,16 +271,16 @@ export class SmartDrawHandler extends ObservableReactComponent { createImageWithFirefly = (input: string, seed?: number, changeInPlace?: boolean): Promise => { this._lastInput.text = input; const dims = FireflyDimensionsMap[this._imgDims]; - return Networking.PostToServer('/queryFireflyImage', { prompt: input, width: dims.width, height: dims.height, seed: seed }) + return Networking.PostToServer('/queryFireflyImage', { prompt: input, width: dims.width, height: dims.height, seed }) .then(img => { - const seed = img.accessPaths.agnostic.client.match(/\/(\d+)upload/)[1]; + const newseed = img.accessPaths.agnostic.client.match(/\/(\d+)upload/)[1]; if (!changeInPlace) { const imgDoc: Doc = Docs.Create.ImageDocument(img.accessPaths.agnostic.client, { title: input.match(/^(.*?)~~~.*$/)?.[1] || input, nativeWidth: dims.width, nativeHeight: dims.height, ai: 'firefly', - ai_firefly_seed: seed, + ai_firefly_seed: newseed, ai_firefly_prompt: input, }); DocumentViewInternal.addDocTabFunc(imgDoc, OpenWhere.addRight); @@ -306,7 +306,7 @@ export class SmartDrawHandler extends ObservableReactComponent { case DocumentType.IMG: if (this._regenInput) { // if (this._selectedDoc) { - const newPrompt = `${doc.ai_firefly_prompt} ~~~ ${this._regenInput}`; + const newPrompt = doc.ai_firefly_prompt ? `${doc.ai_firefly_prompt} ~~~ ${this._regenInput}` : this._regenInput; return this.createImageWithFirefly(newPrompt, NumCast(doc?.ai_firefly_seed), changeInPlace); // } } -- cgit v1.2.3-70-g09d2