Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Surface prompt template variables on the upload form when selected tags or folders use {{name}} placeholders

Murtaza Nasir46473d60f829
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 0a1af761..ead49453 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -395,6 +395,8 @@ document.addEventListener('DOMContentLoaded', async () => {
const uploadHotwords = ref('');
const uploadInitialPrompt = ref('');
const uploadTranscriptionModel = ref('');
+ const uploadPromptVariables = reactive({}); // {variableName: value}
+ const showPromptVariablesPanel = ref(true); // expander state
const transcriptionModelOptions = ref([]);
// Tag Selection
@@ -619,6 +621,61 @@ document.addEventListener('DOMContentLoaded', async () => {
// --- Computed properties needed by composables ---
const isMobileScreen = computed(() => windowWidth.value < 1024);
+
+ // Aggregate `{{name}}` variables across the currently selected
+ // tags and folder. Returns an array of unique entries in the
+ // order they were first seen, each with the inferred label and
+ // a list of contributing sources for the UI to show next to the
+ // input.
+ const _PROMPT_VAR_RE = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g;
+ const _extractVariableNames = (text) => {
+ if (!text || typeof text !== 'string') return [];
+ const names = [];
+ for (const match of text.matchAll(_PROMPT_VAR_RE)) {
+ if (!names.includes(match[1])) names.push(match[1]);
+ }
+ return names;
+ };
+ const _inferVarLabel = (name) => {
+ if (!name) return '';
+ const cleaned = name.replace(/_/g, ' ').trim();
+ if (!cleaned) return '';
+ return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
+ };
+ const selectedPromptVariables = computed(() => {
+ const acc = new Map(); // name -> { label, sources: [{type, name}] }
+ 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 });
+ }
+ }
+ };
+
+ // Tags: scan custom_prompt of every selected tag.
+ if (Array.isArray(selectedTagIds.value) && Array.isArray(availableTags.value)) {
+ for (const id of selectedTagIds.value) {
+ const tag = availableTags.value.find(t => t.id === id);
+ if (tag && tag.custom_prompt) {
+ addVars(tag.custom_prompt, tag.name, 'tag');
+ }
+ }
+ }
+
+ // Folder: scan custom_prompt of the selected folder.
+ if (selectedFolderId.value && Array.isArray(availableFolders.value)) {
+ const folder = availableFolders.value.find(f => f.id === selectedFolderId.value);
+ if (folder && folder.custom_prompt) {
+ addVars(folder.custom_prompt, folder.name, 'folder');
+ }
+ }
+
+ 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) ||
@@ -691,7 +748,7 @@ document.addEventListener('DOMContentLoaded', async () => {
maxConcurrentUploads, recordingDisclaimer, showRecordingDisclaimerModal, pendingRecordingMode,
uploadDisclaimer, showUploadDisclaimerModal,
customBanner, showBanner,
- showAdvancedOptions, userTranscriptionLanguage, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, transcriptionModelOptions,
+ showAdvancedOptions, userTranscriptionLanguage, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, uploadPromptVariables, showPromptVariablesPanel, selectedPromptVariables, transcriptionModelOptions,
availableTags, selectedTagIds, uploadTagSearchFilter,
availableFolders, selectedFolderId, foldersEnabled, filterFolder,
diff --git a/static/js/modules/composables/upload.js b/static/js/modules/composables/upload.js
index 87eca6b2..77f54564 100644
--- a/static/js/modules/composables/upload.js
+++ b/static/js/modules/composables/upload.js
@@ -35,7 +35,7 @@ export function useUpload(state, utils) {
isProcessingActive, pollInterval, progressPopupMinimized, progressPopupClosed,
maxFileSizeMB, chunkingEnabled, chunkingMode, chunkingLimit, maxConcurrentUploads,
recordings, selectedRecording, totalRecordings, globalError,
- selectedTagIds, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, transcriptionModelOptions,
+ selectedTagIds, uploadLanguage, uploadMinSpeakers, uploadMaxSpeakers, uploadHotwords, uploadInitialPrompt, uploadTranscriptionModel, uploadPromptVariables, transcriptionModelOptions,
useAsrEndpoint, connectorSupportsDiarization, asrLanguage, asrMinSpeakers, asrMaxSpeakers,
dragover, availableTags, uploadTagSearchFilter,
// Folder state
@@ -265,6 +265,7 @@ export function useUpload(state, utils) {
hotwords: uploadHotwords.value,
initial_prompt: uploadInitialPrompt.value,
transcription_model: uploadTranscriptionModel.value,
+ prompt_variables: { ...uploadPromptVariables },
};
item.folder_id = selectedFolderId.value;
}
@@ -390,6 +391,22 @@ export function useUpload(state, utils) {
formData.append('transcription_model', transcriptionModel.trim());
}
+ // Per-recording prompt template variables (issue #253). Carry the
+ // values either from a queued item's saved options or from the
+ // current upload-form state. The server sanitises before storing.
+ const promptVariables = asrOpts.prompt_variables || uploadPromptVariables;
+ 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);
+ }
+ }
+ if (Object.keys(cleaned).length > 0) {
+ formData.append('prompt_variables', JSON.stringify(cleaned));
+ }
+ }
+
// Use XMLHttpRequest for per-file upload progress
const data = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
diff --git a/templates/components/upload-view.html b/templates/components/upload-view.html
index 2d9cf21f..4d93ec61 100644
--- a/templates/components/upload-view.html
+++ b/templates/components/upload-view.html
@@ -324,6 +324,42 @@
</p>
</div>
+ <!-- Prompt template variables (from selected tag/folder custom prompts) -->
+ <div v-if="selectedPromptVariables.length > 0" class="mt-4">
+ <button type="button" @click="showPromptVariablesPanel = !showPromptVariablesPanel"
+ class="w-full flex items-center justify-between px-3 py-2 bg-[var(--bg-tertiary)] rounded-md hover:bg-[var(--bg-accent)] transition-colors text-xs font-medium">
+ <span class="flex items-center gap-2 text-[var(--text-secondary)]">
+ <i class="fas fa-keyboard text-[var(--text-muted)]"></i>
+ <span>Prompt variables</span>
+ <span class="text-[10px] text-[var(--text-muted)]">(${ selectedPromptVariables.length })</span>
+ </span>
+ <i :class="['fas text-[var(--text-muted)]', showPromptVariablesPanel ? 'fa-chevron-up' : 'fa-chevron-down']"></i>
+ </button>
+ <div v-show="showPromptVariablesPanel" class="mt-2 p-3 bg-[var(--bg-tertiary)] rounded-md space-y-3 border border-[var(--border-secondary)]">
+ <p class="text-[11px] text-[var(--text-muted)] leading-snug">
+ The selected tag or folder uses prompt placeholders. Fill these in and they'll be substituted into the summarisation prompt for this recording.
+ </p>
+ <div v-for="variable in selectedPromptVariables" :key="variable.name" class="space-y-1">
+ <label class="block text-xs font-medium text-[var(--text-secondary)]" :for="'pv-' + 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="src.type === 'folder' ? 'fas fa-folder' : 'fas fa-tag'" class="mr-0.5"></i>${ src.name }
+ </span>
+ </span>
+ </label>
+ <textarea
+ :id="'pv-' + variable.name"
+ :value="uploadPromptVariables[variable.name] || ''"
+ @input="uploadPromptVariables[variable.name] = $event.target.value"
+ rows="2"
+ :placeholder="'Enter ' + variable.label.toLowerCase() + '...'"
+ class="w-full px-2 py-1 text-sm bg-[var(--bg-primary)] text-[var(--text-primary)] border border-[var(--border-primary)] rounded focus:outline-none focus:ring-1 focus:ring-[var(--ring-focus)] resize-y font-mono"></textarea>
+ </div>
+ </div>
+ </div>
+
<!-- Advanced Options for diarization-enabled connectors (collapsible) -->
<div v-if="connectorSupportsDiarization" class="mt-4">
<button @click="showAdvancedOptions = !showAdvancedOptions"