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: example prompt per image workflow, remember the last prompt (#11775)
Michael Han9a8f2462a269
diff --git a/studio/frontend/src/features/audio/audio-page.tsx b/studio/frontend/src/features/audio/audio-page.tsxindex eb758fc773a..75a0cab8c30 100644--- a/studio/frontend/src/features/audio/audio-page.tsx+++ b/studio/frontend/src/features/audio/audio-page.tsx@@ -110,6 +110,7 @@ import {} from "@/lib/gallery-flags";import { subscribeModelLifecycle } from "@/lib/model-lifecycle-events";import { toast } from "@/lib/toast";+import { readLastPrompt, saveLastPrompt } from "@/lib/last-prompt";import { cn } from "@/lib/utils";import { useIsMobileShell } from "@/hooks/use-mobile";import { useNavigate, useSearch } from "@tanstack/react-router";@@ -312,7 +313,8 @@ export function AudioPage({const generationPresentation = audioGenerationPresentation(generationPhase);const [status, setStatus] = useState<InferenceStatusResponse | null>(null);- const [prompt, setPrompt] = useState("");+ // Starts from the last text generated with.+ const [prompt, setPrompt] = useState(() => readLastPrompt("audio", ""));const [audioInstructions, setAudioInstructions] = useState("");const [audioLanguage, setAudioLanguage] = useState("");const [temperature, setTemperature] = useState(0.6);@@ -1929,6 +1931,7 @@ export function AudioPage({return;}const language = audioLanguage.trim();+ saveLastPrompt("audio", prompt);const controller = new AbortController();generateAbort.current = controller;updateGenerationPhase("generating");@@ -3266,7 +3269,11 @@ export function AudioPage({)}<buttontype="button"- onClick={() => selectClip(clip.id)}+ onClick={() => {+ selectClip(clip.id);+ // Show the text this clip was made with.+ setPrompt(clip.prompt);+ }}aria-current={clip.id === selectedId ? "true" : undefined}diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex 453308af0ff..81bd19668ba 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -2,7 +2,15 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0import { readImageModel, rememberImageModel, matchesRememberedModel, type RememberedImageModel } from "./image-model-recall";-import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";+import {+ type ReactNode,+ type SetStateAction,+ useCallback,+ useEffect,+ useMemo,+ useRef,+ useState,+} from "react";import {ArrowLeftRightIcon,ArrowUpDownIcon,@@ -98,9 +106,10 @@ import {sortGalleryItems,subscribeGalleryChanged,} from "@/lib/gallery-flags";+import { readLastPrompt, saveLastPrompt } from "@/lib/last-prompt";import { usePersistedToggle } from "@/hooks/use-persisted-toggle";import { useImageWorkflowStore } from "./stores/image-workflow-store";-import { WORKFLOW_TABS, type WorkflowId } from "./workflows";+import { WORKFLOW_EXAMPLE_PROMPTS, WORKFLOW_TABS, type WorkflowId } from "./workflows";import { ParamSlider } from "@/features/chat";import { ModelLoadDescription } from "@/features/chat/components/model-load-status";import {@@ -1238,8 +1247,26 @@ export function ImagesPage({const imageModels = useImageModels(hostClass, denseQuantSchemes);const { rootStyle: railRootStyle } = useMediaRailWidth("images");const [quant, setQuant] = useState<string | null>(galleryCache.quant);- const [prompt, setPrompt] = useState(- "Cinematic wide shot of a whimsical Alice in Wonderland tea party in an overgrown Victorian garden. Exactly three figures at a long white lace-draped table: a tall eccentric gentleman in an oversized emerald velvet top hat pouring tea from a silver pot mid-motion; a young woman in a pale blue Victorian dress seated left, holding a porcelain teacup with both hands, looking up and laughing; an older woman in deep burgundy seated right in profile, reaching for a tiered cake stand. Detailed embroidered fabrics, realistic skin texture, natural expressions. The table holds mismatched porcelain, antique silverware, towering pastel cakes, and wildflowers. Giant red-capped mushrooms rise behind the table, with ancient trees overhead and golden sunlight streaming through leaves. Shot on 85mm, f/2.8, focus on the gentleman, soft background falloff. Photorealistic, saturated storybook color, warm amber and deep green palette.",+ // One prompt per workflow: each starts from its example, then the last one generated with.+ const [prompts, setPrompts] = useState<Record<WorkflowId, string>>(() =>+ Object.fromEntries(+ WORKFLOW_TABS.map(({ id }) => [+ id,+ readLastPrompt(`images:${id}`, WORKFLOW_EXAMPLE_PROMPTS[id]),+ ]),+ ) as Record<WorkflowId, string>,+ );+ const setPromptFor = useCallback((id: WorkflowId, next: SetStateAction<string>) => {+ setPrompts((prev) => ({+ ...prev,+ [id]: typeof next === "function" ? next(prev[id]) : next,+ }));+ }, []);+ // Writes the active workflow's prompt, read at call time so a stale closure cannot write another's.+ const setPrompt = useCallback(+ (next: SetStateAction<string>) =>+ setPromptFor(useImageWorkflowStore.getState().workflow, next),+ [setPromptFor],);const [negativePrompt, setNegativePrompt] = useState("");const [negativeOpen, setNegativeOpen] = useState(false);@@ -1289,6 +1316,7 @@ export function ImagesPage({// Active workflow tab: create = text-to-image, transform = img2img, inpaint = mask-guided// redraw. Workflow and page mode live in a store so the sidebar submenu can drive them.const workflow = useImageWorkflowStore((s) => s.workflow);+ const prompt = prompts[workflow];const setWorkflow = useImageWorkflowStore((s) => s.setWorkflow);const supported = useImageWorkflowStore((s) => s.supported);const setSupported = useImageWorkflowStore((s) => s.setSupported);@@ -2115,7 +2143,6 @@ export function ImagesPage({);const restoreSettings = useCallback((image: GalleryImage) => {- setPrompt(image.prompt);// Negative prompt only applies when guidance>0; do not restore a hidden value.const restoredNegative = image.guidance > 0 ? (image.negative_prompt ?? "") : "";setNegativePrompt(restoredNegative);@@ -2156,6 +2183,7 @@ export function ImagesPage({const reopened: WorkflowId =image.workflow === "edit" ? "edit" : image.workflow === "reference" ? "reference" : "create";setWorkflow(reopened);+ setPromptFor(reopened, image.prompt);setInitImage(null);setMaskImage(null);setReferenceImages(@@ -2185,7 +2213,7 @@ export function ImagesPage({} else {toast.success("Settings restored to inputs", rescaled);}- }, [setWorkflow, sizeLimits]);+ }, [setPromptFor, setWorkflow, sizeLimits]);// A locked ratio keeps the paired dimension in step; "custom" frees both, Flip swaps W/H. ratioHW is h/w for [a,b].const ratioHW = (a: number, b: number) => (portrait ? a / b : b / a);@@ -3807,6 +3835,8 @@ export function ImagesPage({return;}+ // Saved only once the request passes validation, so a rejected attempt is not kept.+ saveLastPrompt(`images:${workflow}`, prompt);setBusy("generating");setGenDone(0);setGenStep(null);@@ -5319,7 +5349,11 @@ export function ImagesPage({)}<buttontype="button"- onClick={() => setSelectedId(image.id)}+ onClick={() => {+ setSelectedId(image.id);+ // Show the prompt this image was made with.+ setPrompt(image.prompt);+ }}className="relative size-full overflow-hidden rounded-[10px] bg-muted/40 outline-none ring-1 ring-transparent transition-shadow hover:ring-border focus-visible:ring-2 focus-visible:ring-ring">{srcById[image.id] ? (diff --git a/studio/frontend/src/features/images/workflows.ts b/studio/frontend/src/features/images/workflows.tsindex ed003d4927e..5eac5957c2f 100644--- a/studio/frontend/src/features/images/workflows.ts+++ b/studio/frontend/src/features/images/workflows.ts@@ -85,3 +85,20 @@ export const WORKFLOW_TABS: Array<{hint: "Generate guided by a reference image",},];++/** Starter prompt per workflow, showing what each one is for. */+export const WORKFLOW_EXAMPLE_PROMPTS: Record<WorkflowId, string> = {+ create:+ "A cozy wooden cabin on a snowy mountain at dusk, warm light glowing from the windows, pine trees and gently falling snow. Cinematic photo, soft golden light.",+ edit: "Make the sky a bright sunset orange and add a red kite flying above the trees.",+ transform:+ "Turn this into a watercolor painting with soft pastel colors and loose, visible brush strokes.",+ inpaint:+ "A fluffy orange cat curled up asleep in the painted area, soft window light, realistic fur.",+ extend:+ "Continue the scene outward with more sandy beach, gentle waves and palm trees under a clear blue sky.",+ upscale: "Sharp, highly detailed photo with crisp textures, clean edges and natural colors.",+ reference:+ "The character from the reference exploring a neon lit city street at night, cinematic lighting.",+};+diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsxindex f2f70e4ff78..8081be96d51 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -38,6 +38,7 @@ import {sortGalleryItems,subscribeGalleryChanged,} from "@/lib/gallery-flags";+import { readLastPrompt, saveLastPrompt } from "@/lib/last-prompt";import { useDiffusionGpuChoices } from "@/hooks/use-gpu-info";import { useHardwareInfo } from "@/hooks/use-hardware-info";import { usePersistedToggle } from "@/hooks/use-persisted-toggle";@@ -907,8 +908,12 @@ function VideoGenerator({const denseQuantSchemes = useDenseQuantSchemes();const videoModels = useVideoModels(hostClass, denseQuantSchemes);const [quant, setQuant] = useState<string | null>(galleryCache.quant);- const [prompt, setPrompt] = useState(- "Ultra-realistic cinematic documentary footage of a quiet Kyoto neighborhood at sunrise. An elderly Japanese man opens his traditional wooden shop while a young woman wearing a simple kimono walks past carrying a small basket. Cherry blossom petals gently fall through the air, bicycles pass by, warm sunlight enters between narrow streets, distant temple bells echo. The camera slowly moves forward like a professional travel documentary, realistic human movements, natural expressions, authentic Japanese architecture, subtle wind movement in clothing and trees, realistic colors, 35mm film photography style.",+ // Starts from the last prompt generated with, else a short example.+ const [prompt, setPrompt] = useState(() =>+ readLastPrompt(+ "video",+ "A slow cinematic shot down a quiet Kyoto street at sunrise, cherry blossom petals drifting in the air, a shopkeeper opening a wooden storefront, warm natural light.",+ ),);const [negativePrompt, setNegativePrompt] = useState("");const [negativeOpen, setNegativeOpen] = useState(false);@@ -3263,6 +3268,8 @@ function VideoGenerator({const matchSource = resolutionIdx === MATCH_SOURCE_RESOLUTION;const preset = resolutionPresets[resolutionIdx] ?? resolutionPresets[0];+ // Saved only once the request passes validation, so a rejected attempt is not kept.+ saveLastPrompt("video", prompt);setBusy("generating");setGenStep(null);// The POST only STARTS the job and returns at once (a clip takes minutes, and the secure-mode@@ -4352,7 +4359,11 @@ function VideoGenerator({<TooltipTrigger asChild={true}><buttontype="button"- onClick={() => setSelectedId(video.id)}+ onClick={() => {+ setSelectedId(video.id);+ // Show the prompt this clip was made with.+ setPrompt(video.prompt);+ }}className="relative flex size-full flex-col justify-end overflow-hidden rounded-[10px] bg-muted/40 outline-none ring-1 ring-transparent transition-shadow hover:ring-border focus-visible:ring-2 focus-visible:ring-ring">{thumbnailById[video.id] ? (diff --git a/studio/frontend/src/lib/last-prompt.ts b/studio/frontend/src/lib/last-prompt.tsnew file mode 100644index 00000000000..9d25e4707b1--- /dev/null+++ b/studio/frontend/src/lib/last-prompt.ts@@ -0,0 +1,25 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++/**+ * The last prompt a media page generated with, kept across reloads. Storage failures fall back to+ * the page's example, so the box is never left without one.+ */+// An "unsloth" key, so another account signing in clears it (transitionBrowserAccount).+const PREFIX = "unsloth_last_prompt:";++export function readLastPrompt(key: string, fallback: string): string {+ try {+ return localStorage.getItem(PREFIX + key) ?? fallback;+ } catch {+ return fallback;+ }+}++export function saveLastPrompt(key: string, prompt: string): void {+ try {+ localStorage.setItem(PREFIX + key, prompt);+ } catch {+ // storage unavailable+ }+}diff --git a/studio/frontend/tests/last-prompt.test.ts b/studio/frontend/tests/last-prompt.test.tsnew file mode 100644index 00000000000..f770fbdaff8--- /dev/null+++ b/studio/frontend/tests/last-prompt.test.ts@@ -0,0 +1,107 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import { test } from "node:test";++import {+ BROWSER_ACCOUNT_KEY,+ transitionBrowserAccount,+} from "../src/lib/account-transition.ts";+import { readLastPrompt, saveLastPrompt } from "../src/lib/last-prompt.ts";+import { WORKFLOW_EXAMPLE_PROMPTS, WORKFLOW_TABS } from "../src/features/images/workflows.ts";++function withStorage(storage: unknown, run: () => void) {+ const prev = Object.getOwnPropertyDescriptor(globalThis, "localStorage");+ Object.defineProperty(globalThis, "localStorage", { value: storage, configurable: true });+ try {+ run();+ } finally {+ if (prev) Object.defineProperty(globalThis, "localStorage", prev);+ else delete (globalThis as { localStorage?: unknown }).localStorage;+ }+}++test("the last prompt survives a reload and falls back to the example", () => {+ const store = new Map<string, string>();+ const storage = {+ getItem: (k: string) => store.get(k) ?? null,+ setItem: (k: string, v: string) => void store.set(k, v),+ };+ withStorage(storage, () => {+ assert.equal(readLastPrompt("images:edit", "example"), "example");+ saveLastPrompt("images:edit", "make it blue");+ assert.equal(readLastPrompt("images:edit", "example"), "make it blue");+ // Keys are separate per page and workflow.+ assert.equal(readLastPrompt("images:create", "example"), "example");+ });+});++test("unavailable storage still yields the example", () => {+ const broken = {+ getItem: () => {+ throw new Error("denied");+ },+ setItem: () => {+ throw new Error("denied");+ },+ };+ withStorage(broken, () => {+ saveLastPrompt("video", "x");+ assert.equal(readLastPrompt("video", "example"), "example");+ });+});++test("every image workflow has its own short example prompt", () => {+ const examples = WORKFLOW_TABS.map(({ id }) => WORKFLOW_EXAMPLE_PROMPTS[id]);+ assert.equal(new Set(examples).size, WORKFLOW_TABS.length);+ for (const example of examples) {+ assert.ok(example.length > 0 && example.length < 200);+ assert.ok(!example.includes("\u2014"));+ }+});++function accountBrowser(account: string) {+ const data = new Map([[BROWSER_ACCOUNT_KEY, account]]);+ const localStorage = {+ get length() {+ return data.size;+ },+ key: (index: number) => [...data.keys()][index] ?? null,+ getItem: (key: string) => data.get(key) ?? null,+ setItem: (key: string, value: string) => void data.set(key, value),+ removeItem: (key: string) => void data.delete(key),+ } as unknown as Storage;+ const browser = {+ localStorage,+ sessionStorage: { length: 0, key: () => null, removeItem: () => {} },+ indexedDB: {+ deleteDatabase: () => {+ const request = {} as IDBOpenDBRequest;+ queueMicrotask(() => request.onsuccess?.call(request, {} as IDBVersionChangeEvent));+ return request;+ },+ },+ location: { replace: () => {} },+ } as unknown as Window;+ return { browser, localStorage };+}++test("another account signing in does not see the previous account's prompts", async () => {+ const { browser, localStorage } = accountBrowser("alice");+ withStorage(localStorage, () => saveLastPrompt("images:create", "alice's prompt"));+ await transitionBrowserAccount("bob", "/images", () => {}, browser);+ withStorage(localStorage, () => {+ assert.equal(readLastPrompt("images:create", "example"), "example");+ });+});++test("the same account signing in again keeps its prompts", async () => {+ const { browser, localStorage } = accountBrowser("alice");+ withStorage(localStorage, () => saveLastPrompt("video", "alice's clip"));+ await transitionBrowserAccount("alice", "/video", () => {}, browser);+ withStorage(localStorage, () => {+ assert.equal(readLastPrompt("video", "example"), "alice's clip");+ });+});+