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: clear the old transcript when a transcription fails (#9816)
Nilay40b4702cd39f
diff --git a/studio/frontend/src/features/audio/audio-page.tsx b/studio/frontend/src/features/audio/audio-page.tsxindex 45177ed75e9..5f0c36360fb 100644--- a/studio/frontend/src/features/audio/audio-page.tsx+++ b/studio/frontend/src/features/audio/audio-page.tsx@@ -331,6 +331,7 @@ export function AudioPage({>([]);const [transcript, setTranscript] = useState("");const [transcribedName, setTranscribedName] = useState<string | null>(null);+ const [transcriptError, setTranscriptError] = useState<string | null>(null);const [isRecording, setIsRecording] = useState(false);const [micRequestPending, setMicRequestPending] = useState(false);/** Safari and other WebKit builds ship no MediaRecorder, and an http LAN origin@@ -448,6 +449,12 @@ export function AudioPage({}}, []);+ const clearTranscript = useCallback(() => {+ setTranscript("");+ setTranscribedName(null);+ setTranscriptError(null);+ }, []);+const refreshSttStatus = useCallback(async () => {const generation = ++sttStatusRefreshGeneration.current;try {@@ -504,6 +511,10 @@ export function AudioPage({repoIdForSidecarKey: sttRepoIdForSidecarKey,engineForRepo: sttEngineForRepoId,});+ // Shared sidecar: an adopted model strands the previous pick's transcript+ // under it. null is the 5-minute idle unload, which must not delete it.+ if (reconciled !== null && reconciled !== selectedSttRepoRef.current)+ clearTranscript();selectedSttRepoRef.current = reconciled;setSelectedSttRepo(reconciled);} catch {@@ -511,7 +522,7 @@ export function AudioPage({setSttLoadedModel(null);setSttLoadedEngine(null);}- }, []);+ }, [clearTranscript]);const sttSelected = selectedSttRepo !== null;const sttReady = sttSelectionReady(@@ -533,6 +544,7 @@ export function AudioPage({selectedSttRepoRef.current = null;sttLoadGeneration.current += 1;sttLoadedByThisPage.current = null;+ clearTranscript();setSelectedSttRepo(null);};if (!owned) {@@ -547,7 +559,7 @@ export function AudioPage({await unloadSttModel(sttEngineForRepoId(selected), claim);forget();await refreshSttStatus();- }, [refreshSttStatus, sttReady, sttLoadedModel]);+ }, [clearTranscript, refreshSttStatus, sttReady, sttLoadedModel]);const ensureClipSrc = useCallback(async (clip: AudioGalleryClip) => {const cached = galleryCache.srcById.get(clip.id);@@ -1214,6 +1226,7 @@ export function AudioPage({if (!transitionMode("transcribe")) return;const sidecarKey = sttSidecarKeyFor(id);const engine = sttEngineForRepoId(id);+ if (selectedSttRepoRef.current !== id) clearTranscript();deferredSttLoad.current = null;selectedSttRepoRef.current = id;setSelectedSttRepo(id);@@ -1307,6 +1320,7 @@ export function AudioPage({loadOrStageTtsModel(id, exactGguf, meta);},[+ clearTranscript,ensureSttLoaded,isMac,loadOrStageTtsModel,@@ -1596,6 +1610,8 @@ export function AudioPage({const controller = new AbortController();transcriptionAbort.current = controller;setBusy("transcribing");+ // Or a failure reads as this file's transcript, exported under its name.+ clearTranscript();setTranscribedName(name);try {const text = await transcribeAudioBlob(blob, {@@ -1609,9 +1625,10 @@ export function AudioPage({if (!text) toast.info("The model heard no speech in that audio.");} catch (error) {if (controller.signal.aborted) return;- toast.error(- error instanceof Error ? error.message : "Transcription failed.",- );+ const message =+ error instanceof Error ? error.message : "Transcription failed.";+ if (activeRef.current) setTranscriptError(message);+ toast.error(message);} finally {if (transcriptionAbort.current === controller) {transcriptionAbort.current = null;@@ -1620,7 +1637,13 @@ export function AudioPage({}}},- [selectedSttRepo, sttLoadedModel, sttLoadedEngine, refreshSttStatus],+ [+ clearTranscript,+ selectedSttRepo,+ sttLoadedModel,+ sttLoadedEngine,+ refreshSttStatus,+ ],);const handleRecordToggle = useCallback(async () => {@@ -2254,6 +2277,15 @@ export function AudioPage({{transcript}</p></>+ ) : transcriptError ? (+ <div className="flex flex-col gap-1" role="alert">+ <p className="text-ui-13 font-medium text-destructive">+ Could not transcribe {transcribedName ?? "that audio"}.+ </p>+ <p className="text-ui-13 text-muted-foreground">+ {transcriptError}+ </p>+ </div>) : busy !== "transcribing" ? (<p className="text-ui-13 text-muted-foreground">The transcript appears here. It is not stored: copy ordiff --git a/studio/frontend/tests/audio-transcript-lifecycle.test.ts b/studio/frontend/tests/audio-transcript-lifecycle.test.tsnew file mode 100644index 00000000000..e1f3958aa38--- /dev/null+++ b/studio/frontend/tests/audio-transcript-lifecycle.test.ts@@ -0,0 +1,61 @@+// 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 { readFileSync } from "node:fs";+import test from "node:test";++const source = readFileSync(+ new URL("../src/features/audio/audio-page.tsx", import.meta.url),+ "utf8",+);++test("a transcription run clears the previous result before it awaits", () => {+ // Download .txt used to save A's words under B's name.+ assert.match(+ source,+ /setBusy\("transcribing"\);[\s\S]*?clearTranscript\(\);\s*setTranscribedName\(name\);\s*try \{/,+ );+});++test("a failed transcription is reported in the pane, not only in a toast", () => {+ assert.match(+ source,+ /if \(activeRef\.current\) setTranscriptError\(message\);\s*toast\.error\(message\);/,+ );+ assert.match(+ source,+ /\) : transcriptError \? \([\s\S]*?Could not transcribe \{transcribedName \?\? "that audio"\}/,+ );+});++test("clearing a transcript drops its name and error together", () => {+ assert.match(+ source,+ /const clearTranscript = useCallback\(\(\) => \{\s*setTranscript\(""\);\s*setTranscribedName\(null\);\s*setTranscriptError\(null\);\s*\}, \[\]\);/,+ );+});++test("a transcript never outlives the selection that produced it", () => {+ assert.match(source, /const forget = \(\) => \{[\s\S]*?clearTranscript\(\);/);+ assert.match(+ source,+ /if \(selectedSttRepoRef\.current !== id\) clearTranscript\(\);/,+ );+});++test("a resync that adopts another surface's model clears the transcript too", () => {+ // Chat dictation shares the sidecar, so a resync can adopt an unpicked model.+ assert.match(+ source,+ /const reconciled = reconcileSttSelection\(\{[\s\S]*?\}\);[\s\S]*?if \(reconciled !== null && reconciled !== selectedSttRepoRef\.current\)\s*clearTranscript\(\);\s*selectedSttRepoRef\.current = reconciled;/,+ );+});++test("an idle sidecar unload leaves the transcript the user came back for", () => {+ // The 5-minute idle unload fires while hidden; clearing there loses the text.+ assert.doesNotMatch(+ source,+ /if \(reconciled !== selectedSttRepoRef\.current\) clearTranscript\(\);/,+ );+});