From ee3e991d4e9515c815a9750deba81a7920fe481a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 3 Dec 2023 19:13:42 -0800 Subject: [PATCH] feat: modelfile edit --- src/routes/(app)/modelfiles/+page.svelte | 97 +++- .../(app)/modelfiles/create/+page.svelte | 25 +- .../(app)/modelfiles/edit/[tag]/+page.svelte | 517 ++++++++++++++++++ 3 files changed, 609 insertions(+), 30 deletions(-) create mode 100644 src/routes/(app)/modelfiles/edit/[tag]/+page.svelte diff --git a/src/routes/(app)/modelfiles/+page.svelte b/src/routes/(app)/modelfiles/+page.svelte index e8c24806..e11aad58 100644 --- a/src/routes/(app)/modelfiles/+page.svelte +++ b/src/routes/(app)/modelfiles/+page.svelte @@ -1,8 +1,46 @@
@@ -38,25 +76,48 @@ {#each $modelfiles as modelfile}
- -
-
- modelfile profile + -
-
{modelfile.title}
-
{modelfile.desc}
+
+
{modelfile.title}
+
+ {modelfile.desc} +
+
+
+
+ + Edit + +
- +
{/each}
diff --git a/src/routes/(app)/modelfiles/create/+page.svelte b/src/routes/(app)/modelfiles/create/+page.svelte index 7b8d520c..0db85fbe 100644 --- a/src/routes/(app)/modelfiles/create/+page.svelte +++ b/src/routes/(app)/modelfiles/create/+page.svelte @@ -78,15 +78,15 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); ]; let categories = { - Character: false, - Assistant: false, - Writing: false, - Productivity: false, - Programming: false, - 'Data Analysis': false, - Lifestyle: false, - Education: false, - Business: false + character: false, + assistant: false, + writing: false, + productivity: false, + programming: false, + 'data analysis': false, + lifestyle: false, + education: false, + business: false }; const saveModelfile = async (modelfile) => { @@ -513,7 +513,9 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); class="p-1 px-3 text-xs flex rounded transition" type="button" on:click={() => { - suggestions = [...suggestions, { content: '' }]; + if (suggestions.length === 0 || suggestions.at(-1).content !== '') { + suggestions = [...suggestions, { content: '' }]; + } }} > - -
{category}
+
{category}
{/each}
diff --git a/src/routes/(app)/modelfiles/edit/[tag]/+page.svelte b/src/routes/(app)/modelfiles/edit/[tag]/+page.svelte new file mode 100644 index 00000000..8fcc742c --- /dev/null +++ b/src/routes/(app)/modelfiles/edit/[tag]/+page.svelte @@ -0,0 +1,517 @@ + + +
+
+
+ { + let reader = new FileReader(); + reader.onload = (event) => { + let originalImageUrl = `${event.target.result}`; + + const img = new Image(); + img.src = originalImageUrl; + + img.onload = function () { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + + // Calculate the aspect ratio of the image + const aspectRatio = img.width / img.height; + + // Calculate the new width and height to fit within 100x100 + let newWidth, newHeight; + if (aspectRatio > 1) { + newWidth = 100 * aspectRatio; + newHeight = 100; + } else { + newWidth = 100; + newHeight = 100 / aspectRatio; + } + + // Set the canvas size + canvas.width = 100; + canvas.height = 100; + + // Calculate the position to center the image + const offsetX = (100 - newWidth) / 2; + const offsetY = (100 - newHeight) / 2; + + // Draw the image on the canvas + ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight); + + // Get the base64 representation of the compressed image + const compressedSrc = canvas.toDataURL('image/jpeg'); + + // Display the compressed image + imageUrl = compressedSrc; + + inputFiles = null; + }; + }; + + if ( + inputFiles && + inputFiles.length > 0 && + ['image/gif', 'image/jpeg', 'image/png'].includes(inputFiles[0]['type']) + ) { + reader.readAsDataURL(inputFiles[0]); + } else { + console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`); + inputFiles = null; + } + }} + /> + +
My Modelfiles
+ + +
+ +
{ + updateHandler(); + }} + > +
+
+ +
+
+ +
+
+
Name*
+ +
+ +
+
+ +
+
Model Tag Name*
+ +
+ +
+
+
+ +
+
Description*
+ +
+ +
+
+ +
+
+
Modelfile
+
+ + + +
+
Content*
+ +
+