Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Allow editing stored prompt-variable values from the reprocess summary modal
Murtaza Nasir96cd207ff526
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex 19571d4e..03a7d649 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -1205,6 +1205,13 @@ def reprocess_summary(recording_id):else:current_app.logger.info(f"No custom prompt override provided for recording {recording_id}, will use default priority")+ # Per-recording prompt-template variables. Sanitised through the same+ # helper used at upload time so reprocess can't bypass the caps.+ from src.utils.prompt_variables import sanitize_variable_values+ raw_prompt_variables = data.get('prompt_variables')+ if raw_prompt_variables is not None:+ recording.prompt_variables = sanitize_variable_values(raw_prompt_variables)+# Clear existing summary (status will be set to QUEUED by job_queue.enqueue)recording.summary = Nonediff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex e98814fb..4fa73f2c 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -462,6 +462,11 @@ document.addEventListener('DOMContentLoaded', async () => {const recordingToReset = ref(null);const reprocessType = ref(null);const reprocessRecording = ref(null);+ // Working copy of prompt-template variable values for the reprocess+ // summary modal. Hydrated from `selectedRecording.prompt_variables`+ // when the modal opens; the user can edit them and the values are+ // persisted on the recording when reprocess is submitted.+ const reprocessPromptVariables = reactive({});const isAutoIdentifying = ref(false);const asrReprocessOptions = reactive({language: '',@@ -699,6 +704,52 @@ document.addEventListener('DOMContentLoaded', async () => {return Array.from(acc.values());});++ // Same shape as selectedPromptVariables but for a recording that+ // already has its tags/folder assigned. Used by the reprocess+ // summary modal to render input fields pre-populated from the+ // recording's stored values.+ const reprocessAvailableVariables = computed(() => {+ if (!selectedRecording.value) return [];+ const recording = selectedRecording.value;+ const acc = new Map();+ const addVars = (text, sourceLabel, sourceType) => {+ for (const name of _extractVariableNames(text)) {+ if (!acc.has(name)) {+ acc.set(name, { name, label: _inferVarLabel(name), sources: [] });+ }+ const entry = acc.get(name);+ if (!entry.sources.find(s => s.name === sourceLabel && s.type === sourceType)) {+ entry.sources.push({ type: sourceType, name: sourceLabel });+ }+ }+ };++ let anyTagHasPrompt = false;+ if (Array.isArray(recording.tags)) {+ for (const tag of recording.tags) {+ if (tag && tag.custom_prompt) {+ addVars(tag.custom_prompt, tag.name, 'tag');+ anyTagHasPrompt = true;+ }+ }+ }+ let folderHasPrompt = false;+ if (!anyTagHasPrompt && recording.folder && recording.folder.custom_prompt) {+ addVars(recording.folder.custom_prompt, recording.folder.name, 'folder');+ folderHasPrompt = true;+ }+ let userPromptHasContent = false;+ if (!anyTagHasPrompt && !folderHasPrompt && userSummaryPrompt.value) {+ addVars(userSummaryPrompt.value, 'Your default prompt', 'user');+ userPromptHasContent = true;+ }+ if (!anyTagHasPrompt && !folderHasPrompt && !userPromptHasContent && adminDefaultSummaryPrompt.value) {+ addVars(adminDefaultSummaryPrompt.value, 'Site default prompt', 'admin');+ }++ return Array.from(acc.values());+ });const isMobileDevice = computed(() => {return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||('ontouchstart' in window) ||@@ -771,7 +822,7 @@ document.addEventListener('DOMContentLoaded', async () => {maxConcurrentUploads, recordingDisclaimer, showRecordingDisclaimerModal, pendingRecordingMode,uploadDisclaimer, showUploadDisclaimerModal,customBanner, showBanner,- showAdvancedOptions, userTranscriptionLanguage, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, uploadPromptVariables, showPromptVariablesPanel, selectedPromptVariables, transcriptionModelOptions,+ showAdvancedOptions, userTranscriptionLanguage, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, uploadPromptVariables, showPromptVariablesPanel, selectedPromptVariables, reprocessAvailableVariables, transcriptionModelOptions,availableTags, selectedTagIds, uploadTagSearchFilter,availableFolders, selectedFolderId, foldersEnabled, filterFolder,@@ -807,7 +858,7 @@ document.addEventListener('DOMContentLoaded', async () => {generatedShareLink, existingShareDetected, recordingPublicShares, isLoadingPublicShares,userShares, isLoadingShares, copiedShareId,shareToDelete, showShareDeleteModal, recordingToDelete, recordingToReset,- reprocessType, reprocessRecording, isAutoIdentifying, asrReprocessOptions,+ reprocessType, reprocessRecording, reprocessPromptVariables, isAutoIdentifying, asrReprocessOptions,summaryReprocessPromptSource, summaryReprocessSelectedTagId, summaryReprocessCustomPrompt, summaryReprocessPromptMode,speakerMap, speakerColorMap, modalSpeakers, speakerDisplayMap, regenerateSummaryAfterSpeakerUpdate, speakerSuggestions,loadingSuggestions, activeSpeakerInput, voiceSuggestions, loadingVoiceSuggestions,diff --git a/static/js/modules/composables/reprocess.js b/static/js/modules/composables/reprocess.jsindex cd04a4ee..87c6ce72 100644--- a/static/js/modules/composables/reprocess.js+++ b/static/js/modules/composables/reprocess.js@@ -13,7 +13,7 @@ export function useReprocess(state, utils) {reprocessRecording, recordingToReset, selectedRecording,recordings, asrReprocessOptions, summaryReprocessPromptSource,summaryReprocessSelectedTagId, summaryReprocessCustomPrompt,- summaryReprocessPromptMode,+ summaryReprocessPromptMode, reprocessPromptVariables,availableTags, processingProgress, processingMessage,currentlyProcessingFile, uploadQueue, userTranscriptionLanguage,showCustomizeSummaryModal, customizeSummaryPrompt, customizeSummaryMode@@ -45,6 +45,17 @@ export function useReprocess(state, utils) {summaryReprocessPromptSource.value = 'default';summaryReprocessSelectedTagId.value = '';summaryReprocessCustomPrompt.value = '';++ // Hydrate the reprocess prompt-variables form from the recording's+ // saved values so the user starts with what they had at upload.+ // Drop any existing keys first to keep the reactive object tidy.+ for (const k of Object.keys(reprocessPromptVariables)) {+ delete reprocessPromptVariables[k];+ }+ const stored = (reprocessRecording.value && reprocessRecording.value.prompt_variables) || {};+ for (const [k, v] of Object.entries(stored)) {+ reprocessPromptVariables[k] = v == null ? '' : String(v);+ }}};@@ -132,7 +143,8 @@ export function useReprocess(state, utils) {summaryReprocessPromptSource.value,summaryReprocessSelectedTagId.value,summaryReprocessCustomPrompt.value,- summaryReprocessPromptMode.value+ summaryReprocessPromptMode.value,+ { ...reprocessPromptVariables });}};@@ -193,7 +205,7 @@ export function useReprocess(state, utils) {// Summary Reprocessing// =========================================- const reprocessSummary = async (recordingId, promptSource, selectedTagId, customPrompt, promptMode) => {+ const reprocessSummary = async (recordingId, promptSource, selectedTagId, customPrompt, promptMode, promptVariables) => {if (!recordingId) {setGlobalError('No recording ID provided for reprocessing.');return;@@ -215,6 +227,18 @@ export function useReprocess(state, utils) {requestBody.prompt_mode = mode;}+ // Carry the user-edited prompt-variable values so the recording's+ // stored map gets updated before the summary task runs.+ if (promptVariables && typeof promptVariables === 'object') {+ const cleaned = {};+ for (const [key, value] of Object.entries(promptVariables)) {+ if (value !== undefined && value !== null && String(value).trim() !== '') {+ cleaned[key] = String(value);+ }+ }+ requestBody.prompt_variables = cleaned;+ }+const response = await fetch(`/recording/${recordingId}/reprocess_summary`, {method: 'POST',headers: {diff --git a/templates/modals/reprocess-modal.html b/templates/modals/reprocess-modal.htmlindex 6203c12b..39e9bc22 100644--- a/templates/modals/reprocess-modal.html+++ b/templates/modals/reprocess-modal.html@@ -102,6 +102,40 @@</div></div>+ <!-- Prompt Template Variables -->+ <div v-if="reprocessType === 'summary' && reprocessAvailableVariables.length > 0" class="space-y-3 pt-4 border-t border-[var(--border-primary)]">+ <h4 class="text-md font-semibold text-[var(--text-secondary)] flex items-center gap-2">+ <i class="fas fa-keyboard text-[var(--text-muted)] text-xs"></i>+ Prompt variables+ </h4>+ <p class="text-xs text-[var(--text-muted)] leading-snug">+ These values are substituted into <code>{{ '{{name}}' }}</code> placeholders in the resolved prompt. Edits here are saved on the recording.+ </p>+ <div v-for="variable in reprocessAvailableVariables" :key="variable.name" class="space-y-1">+ <label class="block text-xs font-medium text-[var(--text-secondary)]" :for="'rpv-' + variable.name">+ ${ variable.label }+ <span class="ml-1 text-[10px] text-[var(--text-muted)] font-normal">+ <span v-for="(src, i) in variable.sources" :key="i">+ <span v-if="i > 0">, </span>+ <i :class="{+ 'fas fa-folder': src.type === 'folder',+ 'fas fa-tag': src.type === 'tag',+ 'fas fa-user': src.type === 'user',+ 'fas fa-cog': src.type === 'admin'+ }" class="mr-0.5"></i>${ src.name }+ </span>+ </span>+ </label>+ <textarea+ :id="'rpv-' + variable.name"+ :value="reprocessPromptVariables[variable.name] || ''"+ @input="reprocessPromptVariables[variable.name] = $event.target.value"+ rows="2"+ :placeholder="'Enter ' + variable.label.toLowerCase() + '...'"+ class="w-full px-2 py-1 text-sm bg-[var(--bg-input)] text-[var(--text-primary)] border border-[var(--border-secondary)] rounded focus:outline-none focus:ring-1 focus:ring-[var(--border-focus)] resize-y font-mono"></textarea>+ </div>+ </div>+<!-- Custom Prompt Options for Summary Reprocessing --><div v-if="reprocessType === 'summary'" class="space-y-4 pt-4 border-t border-[var(--border-primary)]"><h4 class="text-md font-semibold text-[var(--text-secondary)]">Custom Summarization Prompt</h4>