Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: add Edit image to the Images gallery item menu (#14162)
Michael Hanb52d34a0f203
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex 8de9e48ec02..36c27e057cd 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -21,6 +21,7 @@ import {Refresh01Icon,Delete02Icon,Download01Icon,+ Edit03Icon,FolderAddIcon,Image03Icon,ImageAdd02Icon,@@ -146,7 +147,7 @@ import {saveLastPrompt,} from "@/lib/last-prompt";import { usePersistedToggle } from "@/hooks/use-persisted-toggle";-import { useImageWorkflowStore } from "./stores/image-workflow-store";+import { isWorkflowEnabled, useImageWorkflowStore } from "./stores/image-workflow-store";import {WORKFLOW_EXAMPLE_PROMPTS,WORKFLOW_TABS,@@ -210,6 +211,7 @@ import {routedGgufLabel,} from "@/lib/diffusion-route-search";import { toast } from "@/lib/toast";+import { MAX_UPLOAD_IMAGE_SIDE, fitImageDataUrl } from "@/lib/image-fit";import { loadGalleryUntil } from "@/lib/gallery-deep-link";import { subscribeModelEjected } from "@/lib/model-lifecycle-events";import {@@ -461,6 +463,16 @@ const RESYNC_MAX_ATTEMPTS = 3;// For example Unsloth_20260624-143005_123.png.type ImageExportFormat = "png" | "jpeg" | "webp";+function blobToDataUrl(blob: Blob): Promise<string> {+ return new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = () =>+ typeof reader.result === "string" ? resolve(reader.result) : reject(new Error("Could not read the image"));+ reader.onerror = () => reject(reader.error ?? new Error("Could not read the image"));+ reader.readAsDataURL(blob);+ });+}+function exportFilename(image: GalleryImage, format: ImageExportFormat = "png"): string {const d = new Date(image.created_at * 1000);const p = (n: number) => String(n).padStart(2, "0");@@ -3348,6 +3360,51 @@ export function ImagesPage({setMaskImage(null);setMaskResetKey((k) => k + 1);}, []);+ // Only the newest click applies: the gallery fetch can outlive a second one.+ const editRequest = useRef(0);+ const editGalleryImage = useCallback(+ async (image: GalleryImage) => {+ const claimed = ++editRequest.current;+ let dataUrl: string;+ try {+ const blob = await fetchGalleryBlob(image.url);+ dataUrl = await fitImageDataUrl(await blobToDataUrl(blob), MAX_UPLOAD_IMAGE_SIDE);+ } catch (error) {+ if (claimed === editRequest.current) {+ toast.error("Could not open the image for editing", {+ description: error instanceof Error ? error.message : String(error),+ });+ }+ return;+ }+ if (claimed !== editRequest.current) return;+ const target: WorkflowId | null = isWorkflowEnabled("edit", supported)+ ? "edit"+ : isWorkflowEnabled("transform", supported)+ ? "transform"+ : null;+ if (target) setWorkflow(target);+ handleInitChange(dataUrl);+ if (target === "edit") {+ toast.success("Image added to Edit. Describe the change and hit Generate.");+ } else if (target === "transform") {+ toast.success("Image added to Transform", {+ description: "The loaded model cannot follow edit instructions, so it redraws the image from your prompt.",+ });+ } else {+ toast.info("Image set as the source", {+ description: "The loaded model cannot edit images. Load an edit model, then pick Edit.",+ });+ }+ },+ [supported, setWorkflow, handleInitChange],+ );+ const editImageItem = (image: GalleryImage) => (+ <DropdownMenuItem onClick={() => void editGalleryImage(image)}>+ <HugeiconsIcon icon={Edit03Icon} strokeWidth={1.75} className="size-icon" />+ Edit image+ </DropdownMenuItem>+ );const { openCrop: openInpaintCrop, cropDialog: inpaintCropDialog } = useImageCrop(initImage,handleInitChange,@@ -6220,6 +6277,7 @@ export function ImagesPage({onDelete={() => void handleDelete(selected.id)}onDownload={() => void handleQuickDownload(selected)}onAddToProject={(projectId) => addGalleryImageToProject(selected.id, projectId)}+ leadingItems={editImageItem(selected)}/></div></>@@ -6384,6 +6442,7 @@ export function ImagesPage({onDelete={() => void handleDelete(image.id)}onDownload={() => void handleQuickDownload(image)}onAddToProject={(projectId) => addGalleryImageToProject(image.id, projectId)}+ leadingItems={editImageItem(image)}/></div></div>