Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Keep character names in rewritten prompts

Bowen Xue70e8210eefdf
diff --git a/web/cast_mention.js b/web/cast_mention.js
index c243c25..cfe34e0 100644
--- a/web/cast_mention.js
+++ b/web/cast_mention.js
@@ -94,7 +94,8 @@ export function mentionRanges(text, people) {
// pictures are gone is written as a plain name. `active: false` (first/last frames) leaves every name plain too, since
// pictures of people cannot go with those. `continued` (the part continues a video) lets the characters stay: the part
// keeps three reference pictures (see pictureNumbers) and its frames come after them, so a character whose pictures are
-// not among those three is written as a plain name.
+// not among those three is written as a plain name. A rewritten prompt already opens with its own subject definitions
+// (the rewrite writes them in H3's ref2va form); only its names become <Subject N> then.
export function expandCast(text, rows, {active = true, continued = false} = {}) {
text = String(text ?? '');
const list = Array.isArray(rows) ? rows : [];
@@ -125,11 +126,22 @@ export function expandCast(text, rows, {active = true, continued = false} = {})
const last = ranges[ranges.length - 1];
if (last && number === last[1] + 1) last[1] = number; else ranges.push([number, number]);
}
- return {name: person.name, description: person.description, pictures: ranges, audio: null};
+ return {name: person.name, handle: person.handle ?? person.name, description: person.description, pictures: ranges, audio: null};
});
+ if (/^\s*subject_definitions:/.test(text)) return {text: result, subjects};
return {text: subjectDefinitions(subjects) + '\n\n' + result, subjects};
}
+// The rewrite of an expanded prompt, written back with the names the box had: <Subject N> becomes "@handle" of the
+// subject expandCast gave that number. A rewrite with a number that stands for no one is kept as it came.
+export function restoreCast(text, subjects) {
+ text = String(text ?? '');
+ const handles = (Array.isArray(subjects) ? subjects : []).map(subject => subject.handle ?? subject.name);
+ const numbers = [...text.matchAll(/<Subject (\d+)>/g)].map(match => Number(match[1]));
+ if (!numbers.length || numbers.some(number => !handles[number - 1])) return text;
+ return text.replace(/<Subject (\d+)>/g, (_, number) => '@' + handles[number - 1]);
+}
+
// The pictures of a card to put in the media list, as the Agent carries them (agent/drama.py person_pictures): the sheet of
// every view (the card's own, else the one the library made), then the face close-up, else the front view. A card with no
// sheet (one picture, or none could be made) carries its face alone.
diff --git a/web/prompt_enhance.js b/web/prompt_enhance.js
index 19e35dc..5ad99eb 100644
--- a/web/prompt_enhance.js
+++ b/web/prompt_enhance.js
@@ -66,8 +66,9 @@ export function promptPrestart(api, nodeId, enabled, alive = () => true) {
// An empty box is never rewritten, the untouched starter prompt included:
// enhancement waits for the user's own scene.
-// `prepare` turns the user's text into what the model reads (character mentions written out with their pictures).
-export function createPromptEnhancer({node, input, editor, api, context, setText, t, starter = '', prepare = text => text, onReport = () => {}, onChange = () => {}, issueButton = null}) {
+// `prepare` turns the user's text into what the model reads (character mentions written out with their pictures);
+// `restore` turns the rewrite back into what the box shows (the mentions written as the user wrote them).
+export function createPromptEnhancer({node, input, editor, api, context, setText, t, starter = '', prepare = text => text, restore = text => text, onReport = () => {}, onChange = () => {}, issueButton = null}) {
const saved = node.properties?.freevideo_prompt_versions;
// Drafts saved before the starter became a placeholder hold it as the original.
const versions = new PromptVersions(starter && saved?.original === starter ? {...saved, original: ''} : saved, input.value);
@@ -354,7 +355,7 @@ export function createPromptEnhancer({node, input, editor, api, context, setText
}
const result = await poll('rewrite', {text: prepare(original), ...scene});
if (disposed || cancelling) throw new Error('cancelled');
- if (edits !== versions.value.edits || !versions.accept(key, context(), result.text)) throw new Error('stale');
+ if (edits !== versions.value.edits || !versions.accept(key, context(), restore(result.text))) throw new Error('stale');
apply(); show('');
};
running = Promise.resolve().then(execute).catch(error => {
diff --git a/web/studio.js b/web/studio.js
index 925b9cf..f90ddba 100644
--- a/web/studio.js
+++ b/web/studio.js
@@ -24,7 +24,7 @@ import { createStudioQueue, randomSeed, turnNodeOn } from './studio_queue.js';
import { isNetworkTypeError, connectionLostText } from './browser_extension.js';
import { attachReferencePicker, referenceItems, enhancementMedia, syncReferencePrompt, referenceInputs, mentionAt, handleNames, mediaRows } from './prompt_references.js';
import { attachTermSuggest } from './prompt_terms.js';
-import { castInRows, expandCast, mentionHandle, mentionState, mentionedIds, withCharacter, MAX_PICTURES_EACH } from './cast_mention.js';
+import { castInRows, expandCast, mentionHandle, mentionState, mentionedIds, restoreCast, withCharacter, MAX_PICTURES_EACH } from './cast_mention.js';
import { attachMentionOverlay } from './cast_overlay.js';
import { openCastLibrary } from './cast_source.js';
import { uploadMedia } from './media_upload.js';
@@ -817,9 +817,11 @@ export function openStudio(node, {extendFrom = null} = {}) {
cleanup.push(() => { castLibrary?.destroy?.(); castLibrary = null; window.removeEventListener('freevideo-media', castChanged); prompt.removeEventListener('input', announceCast); castOverlay.dispose(); delete node.freevideoContinues; });
openCastLibrary({api, text: t, viewURL: view, uploadOne: castUpload, onChange: () => { castOverlay.refresh(); references.refresh(); }})
.then(library => { if (disposed) library?.destroy?.(); else castLibrary = library; });
- let requestAssets = null;
+ let requestAssets = null, rewriteSubjects = [];
const enhancer = createPromptEnhancer({node, input: prompt, editor: promptEditor, api, t, starter, issueButton,
- prepare: text => expandCast(text, mediaRows(node), {continued: Boolean(extension.source)}).text,
+ // One rewrite runs at a time, so the subjects of the text it was given are the ones its numbers refer to.
+ prepare: text => { const out = expandCast(text, mediaRows(node), {continued: Boolean(extension.source)}); rewriteSubjects = out.subjects; return out.text; },
+ restore: text => restoreCast(text, rewriteSubjects),
// The rewrite has its own report; the video's report entry is not touched.
onReport: row => { node.freevideoPromptReportId = row.rewrite_report_id || row.report_id; },
onChange: () => { rememberPromptDraft(api, node); requestAssets?.refresh(); },