Spaces:
Sleeping
Sleeping
Julian Bilcke
commited on
Commit
·
d303a22
1
Parent(s):
11809c3
try to fix the nb of panels issue
Browse files
src/app/main.tsx
CHANGED
|
@@ -75,16 +75,13 @@ export default function Main() {
|
|
| 75 |
currentPanel < nbTotalPanels;
|
| 76 |
currentPanel += nbPanelsToGenerate
|
| 77 |
) {
|
| 78 |
-
if (currentPanel > (nbTotalPanels / 2)) {
|
| 79 |
-
console.log("good, we are half way there, hold tight!")
|
| 80 |
-
// setWaitABitMore(true)
|
| 81 |
-
}
|
| 82 |
try {
|
| 83 |
const candidatePanels = await getStoryContinuation({
|
| 84 |
preset,
|
| 85 |
stylePrompt,
|
| 86 |
userStoryPrompt,
|
| 87 |
nbPanelsToGenerate,
|
|
|
|
| 88 |
existingPanels,
|
| 89 |
})
|
| 90 |
console.log("LLM generated some new panels:", candidatePanels)
|
|
@@ -123,6 +120,10 @@ export default function Main() {
|
|
| 123 |
setGeneratingStory(false)
|
| 124 |
break
|
| 125 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
/*
|
|
|
|
| 75 |
currentPanel < nbTotalPanels;
|
| 76 |
currentPanel += nbPanelsToGenerate
|
| 77 |
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
try {
|
| 79 |
const candidatePanels = await getStoryContinuation({
|
| 80 |
preset,
|
| 81 |
stylePrompt,
|
| 82 |
userStoryPrompt,
|
| 83 |
nbPanelsToGenerate,
|
| 84 |
+
nbTotalPanels,
|
| 85 |
existingPanels,
|
| 86 |
})
|
| 87 |
console.log("LLM generated some new panels:", candidatePanels)
|
|
|
|
| 120 |
setGeneratingStory(false)
|
| 121 |
break
|
| 122 |
}
|
| 123 |
+
if (currentPanel > (nbTotalPanels / 2)) {
|
| 124 |
+
console.log("good, we are half way there, hold tight!")
|
| 125 |
+
// setWaitABitMore(true)
|
| 126 |
+
}
|
| 127 |
}
|
| 128 |
|
| 129 |
/*
|
src/app/queries/getStoryContinuation.ts
CHANGED
|
@@ -8,13 +8,15 @@ export const getStoryContinuation = async ({
|
|
| 8 |
stylePrompt = "",
|
| 9 |
userStoryPrompt = "",
|
| 10 |
nbPanelsToGenerate = 2,
|
|
|
|
| 11 |
existingPanels = [],
|
| 12 |
}: {
|
| 13 |
preset: Preset;
|
| 14 |
-
stylePrompt
|
| 15 |
-
userStoryPrompt
|
| 16 |
-
nbPanelsToGenerate
|
| 17 |
-
|
|
|
|
| 18 |
}): Promise<GeneratedPanel[]> => {
|
| 19 |
|
| 20 |
let panels: GeneratedPanel[] = []
|
|
@@ -29,6 +31,7 @@ export const getStoryContinuation = async ({
|
|
| 29 |
preset,
|
| 30 |
prompt,
|
| 31 |
nbPanelsToGenerate,
|
|
|
|
| 32 |
existingPanels,
|
| 33 |
})
|
| 34 |
|
|
@@ -49,7 +52,7 @@ export const getStoryContinuation = async ({
|
|
| 49 |
// console.log("LLM step failed due to:", err)
|
| 50 |
// console.log("we are now switching to a degraded mode, using 4 similar panels")
|
| 51 |
panels = []
|
| 52 |
-
for (let p = startAt; p < endAt; p++) {
|
| 53 |
panels.push({
|
| 54 |
panel: p,
|
| 55 |
instructions: joinWords([
|
|
|
|
| 8 |
stylePrompt = "",
|
| 9 |
userStoryPrompt = "",
|
| 10 |
nbPanelsToGenerate = 2,
|
| 11 |
+
nbTotalPanels = 8,
|
| 12 |
existingPanels = [],
|
| 13 |
}: {
|
| 14 |
preset: Preset;
|
| 15 |
+
stylePrompt?: string;
|
| 16 |
+
userStoryPrompt?: string;
|
| 17 |
+
nbPanelsToGenerate?: number;
|
| 18 |
+
nbTotalPanels?: number;
|
| 19 |
+
existingPanels?: GeneratedPanel[];
|
| 20 |
}): Promise<GeneratedPanel[]> => {
|
| 21 |
|
| 22 |
let panels: GeneratedPanel[] = []
|
|
|
|
| 31 |
preset,
|
| 32 |
prompt,
|
| 33 |
nbPanelsToGenerate,
|
| 34 |
+
nbTotalPanels,
|
| 35 |
existingPanels,
|
| 36 |
})
|
| 37 |
|
|
|
|
| 52 |
// console.log("LLM step failed due to:", err)
|
| 53 |
// console.log("we are now switching to a degraded mode, using 4 similar panels")
|
| 54 |
panels = []
|
| 55 |
+
for (let p = startAt; p < endAt && p; p++) {
|
| 56 |
panels.push({
|
| 57 |
panel: p,
|
| 58 |
instructions: joinWords([
|
src/app/queries/predictNextPanels.ts
CHANGED
|
@@ -11,11 +11,13 @@ export const predictNextPanels = async ({
|
|
| 11 |
preset,
|
| 12 |
prompt = "",
|
| 13 |
nbPanelsToGenerate = 2,
|
|
|
|
| 14 |
existingPanels = [],
|
| 15 |
}: {
|
| 16 |
preset: Preset;
|
| 17 |
prompt: string;
|
| 18 |
-
nbPanelsToGenerate
|
|
|
|
| 19 |
existingPanels: GeneratedPanel[];
|
| 20 |
}): Promise<GeneratedPanel[]> => {
|
| 21 |
// console.log("predictNextPanels: ", { prompt, nbPanelsToGenerate })
|
|
@@ -28,12 +30,20 @@ export const predictNextPanels = async ({
|
|
| 28 |
? ` To help you, here are the previous panels and their captions (note: if you see an anomaly here eg. no caption or the same description repeated multiple times, do not hesitate to fix the story): ${JSON.stringify(existingPanels, null, 2)}`
|
| 29 |
: ''
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
const query = createZephyrPrompt([
|
| 32 |
{
|
| 33 |
role: "system",
|
| 34 |
content: [
|
| 35 |
`You are a writer specialized in ${preset.llmPrompt}`,
|
| 36 |
-
`Please write detailed drawing instructions and short (2-3 sentences long) speech captions for the
|
| 37 |
`Give your response as a VALID JSON array like this: \`Array<{ panel: number; instructions: string; caption: string; }>\`.`,
|
| 38 |
// `Give your response as Markdown bullet points.`,
|
| 39 |
`Be brief in your ${nbPanelsToGenerate} instructions and narrative captions, don't add your own comments. The captions must be captivating, smart, entertaining. Be straight to the point, and never reply things like "Sure, I can.." etc. Reply using valid JSON!! Important: Write valid JSON!`
|
|
|
|
| 11 |
preset,
|
| 12 |
prompt = "",
|
| 13 |
nbPanelsToGenerate = 2,
|
| 14 |
+
nbTotalPanels = 8,
|
| 15 |
existingPanels = [],
|
| 16 |
}: {
|
| 17 |
preset: Preset;
|
| 18 |
prompt: string;
|
| 19 |
+
nbPanelsToGenerate?: number;
|
| 20 |
+
nbTotalPanels?: number;
|
| 21 |
existingPanels: GeneratedPanel[];
|
| 22 |
}): Promise<GeneratedPanel[]> => {
|
| 23 |
// console.log("predictNextPanels: ", { prompt, nbPanelsToGenerate })
|
|
|
|
| 30 |
? ` To help you, here are the previous panels and their captions (note: if you see an anomaly here eg. no caption or the same description repeated multiple times, do not hesitate to fix the story): ${JSON.stringify(existingPanels, null, 2)}`
|
| 31 |
: ''
|
| 32 |
|
| 33 |
+
|
| 34 |
+
const firstNextOrLast =
|
| 35 |
+
existingPanels.length === 0
|
| 36 |
+
? "first"
|
| 37 |
+
: (nbTotalPanels - existingPanels.length) === nbTotalPanels
|
| 38 |
+
? "last"
|
| 39 |
+
: "next"
|
| 40 |
+
|
| 41 |
const query = createZephyrPrompt([
|
| 42 |
{
|
| 43 |
role: "system",
|
| 44 |
content: [
|
| 45 |
`You are a writer specialized in ${preset.llmPrompt}`,
|
| 46 |
+
`Please write detailed drawing instructions and short (2-3 sentences long) speech captions for the ${firstNextOrLast} ${nbPanelsToGenerate} panels (out of ${nbTotalPanels}) of a new story, but keep it open-ended (it will be continued and expanded later). Please make sure each of those ${nbPanelsToGenerate} panels include info about character gender, age, origin, clothes, colors, location, lights, etc.`,
|
| 47 |
`Give your response as a VALID JSON array like this: \`Array<{ panel: number; instructions: string; caption: string; }>\`.`,
|
| 48 |
// `Give your response as Markdown bullet points.`,
|
| 49 |
`Be brief in your ${nbPanelsToGenerate} instructions and narrative captions, don't add your own comments. The captions must be captivating, smart, entertaining. Be straight to the point, and never reply things like "Sure, I can.." etc. Reply using valid JSON!! Important: Write valid JSON!`
|