Spaces:
Sleeping
Sleeping
Julian Bilcke
commited on
Commit
·
690ffd8
1
Parent(s):
cea3188
fix the dual prompting system
Browse files- src/app/interface/top-menu/index.tsx +36 -16
- src/app/main.tsx +17 -5
- src/app/queries/getStory.ts +1 -1
src/app/interface/top-menu/index.tsx
CHANGED
|
@@ -59,11 +59,15 @@ export function TopMenu() {
|
|
| 59 |
const requestedPrompt = (searchParams?.get('prompt') as string) || ""
|
| 60 |
const requestedLayout = (searchParams?.get('layout') as LayoutName) || defaultLayout
|
| 61 |
|
| 62 |
-
const [
|
|
|
|
|
|
|
|
|
|
| 63 |
const [draftPreset, setDraftPreset] = useState<PresetName>(requestedPreset)
|
| 64 |
const [draftLayout, setDraftLayout] = useState<LayoutName>(requestedLayout)
|
| 65 |
|
| 66 |
const handleSubmit = () => {
|
|
|
|
| 67 |
const promptChanged = draftPrompt.trim() !== prompt.trim()
|
| 68 |
const presetChanged = draftPreset !== preset.id
|
| 69 |
const layoutChanged = draftLayout !== layout
|
|
@@ -195,22 +199,38 @@ export function TopMenu() {
|
|
| 195 |
`transition-all duration-200 ease-in-out`,
|
| 196 |
`flex flex-grow flex-col space-y-2 md:space-y-0 md:flex-row items-center md:space-x-3 font-mono w-full md:w-auto`
|
| 197 |
)}>
|
|
|
|
| 198 |
<div className="flex flex-row flex-grow w-full">
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
className={cn(
|
| 215 |
`rounded-l-none cursor-pointer`,
|
| 216 |
`transition-all duration-200 ease-in-out`,
|
|
|
|
| 59 |
const requestedPrompt = (searchParams?.get('prompt') as string) || ""
|
| 60 |
const requestedLayout = (searchParams?.get('layout') as LayoutName) || defaultLayout
|
| 61 |
|
| 62 |
+
const [draftPromptA, setDraftPromptA] = useState(requestedPrompt)
|
| 63 |
+
const [draftPromptB, setDraftPromptB] = useState(requestedPrompt)
|
| 64 |
+
const draftPrompt = `${draftPromptA}||${draftPromptB}`
|
| 65 |
+
|
| 66 |
const [draftPreset, setDraftPreset] = useState<PresetName>(requestedPreset)
|
| 67 |
const [draftLayout, setDraftLayout] = useState<LayoutName>(requestedLayout)
|
| 68 |
|
| 69 |
const handleSubmit = () => {
|
| 70 |
+
|
| 71 |
const promptChanged = draftPrompt.trim() !== prompt.trim()
|
| 72 |
const presetChanged = draftPreset !== preset.id
|
| 73 |
const layoutChanged = draftLayout !== layout
|
|
|
|
| 199 |
`transition-all duration-200 ease-in-out`,
|
| 200 |
`flex flex-grow flex-col space-y-2 md:space-y-0 md:flex-row items-center md:space-x-3 font-mono w-full md:w-auto`
|
| 201 |
)}>
|
| 202 |
+
<div className="flex flex-row flex-grow w-full">
|
| 203 |
<div className="flex flex-row flex-grow w-full">
|
| 204 |
+
<Input
|
| 205 |
+
placeholder="1. style and theme.."
|
| 206 |
+
className="w-1/2 bg-neutral-300 text-neutral-800 dark:bg-neutral-300 dark:text-neutral-800 rounded-r-none"
|
| 207 |
+
// disabled={atLeastOnePanelIsBusy}
|
| 208 |
+
onChange={(e) => {
|
| 209 |
+
setDraftPromptA(e.target.value)
|
| 210 |
+
}}
|
| 211 |
+
onKeyDown={({ key }) => {
|
| 212 |
+
if (key === 'Enter') {
|
| 213 |
+
handleSubmit()
|
| 214 |
+
}
|
| 215 |
+
}}
|
| 216 |
+
value={draftPromptA}
|
| 217 |
+
/>
|
| 218 |
+
<Input
|
| 219 |
+
placeholder="2. add a story.."
|
| 220 |
+
className="w-1/2 bg-neutral-300 text-neutral-800 dark:bg-neutral-300 dark:text-neutral-800 rounded-l-none rounded-r-none"
|
| 221 |
+
// disabled={atLeastOnePanelIsBusy}
|
| 222 |
+
onChange={(e) => {
|
| 223 |
+
setDraftPromptB(e.target.value)
|
| 224 |
+
}}
|
| 225 |
+
onKeyDown={({ key }) => {
|
| 226 |
+
if (key === 'Enter') {
|
| 227 |
+
handleSubmit()
|
| 228 |
+
}
|
| 229 |
+
}}
|
| 230 |
+
value={draftPromptB}
|
| 231 |
+
/>
|
| 232 |
+
</div>
|
| 233 |
+
<Button
|
| 234 |
className={cn(
|
| 235 |
`rounded-l-none cursor-pointer`,
|
| 236 |
`transition-all duration-200 ease-in-out`,
|
src/app/main.tsx
CHANGED
|
@@ -45,8 +45,15 @@ export default function Main() {
|
|
| 45 |
|
| 46 |
let llmResponse: LLMResponse = []
|
| 47 |
|
|
|
|
|
|
|
| 48 |
try {
|
| 49 |
-
llmResponse = await getStory({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
console.log("LLM responded:", llmResponse)
|
| 51 |
|
| 52 |
} catch (err) {
|
|
@@ -66,14 +73,19 @@ export default function Main() {
|
|
| 66 |
|
| 67 |
// we have to limit the size of the prompt, otherwise the rest of the style won't be followed
|
| 68 |
|
| 69 |
-
let
|
| 70 |
-
if (
|
| 71 |
-
console.log("Sorry folks, the prompt was cut to:",
|
| 72 |
}
|
| 73 |
|
| 74 |
// new experimental prompt: let's drop the user prompt!
|
| 75 |
const lightPanelPromptPrefix = preset.imagePrompt("").filter(x => x).join(", ")
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
const newPanels: string[] = []
|
| 79 |
const newCaptions: string[] = []
|
|
|
|
| 45 |
|
| 46 |
let llmResponse: LLMResponse = []
|
| 47 |
|
| 48 |
+
const [stylePrompt, userStoryPrompt] = prompt.split("||")
|
| 49 |
+
|
| 50 |
try {
|
| 51 |
+
llmResponse = await getStory({
|
| 52 |
+
preset,
|
| 53 |
+
prompt: [
|
| 54 |
+
`${userStoryPrompt}`,
|
| 55 |
+
stylePrompt ? `in the following context: ${stylePrompt}` : ''
|
| 56 |
+
].filter(x => x).join(", "), nbTotalPanels })
|
| 57 |
console.log("LLM responded:", llmResponse)
|
| 58 |
|
| 59 |
} catch (err) {
|
|
|
|
| 73 |
|
| 74 |
// we have to limit the size of the prompt, otherwise the rest of the style won't be followed
|
| 75 |
|
| 76 |
+
let limitedStylePrompt = stylePrompt.slice(0, 77)
|
| 77 |
+
if (limitedStylePrompt.length !== stylePrompt.length) {
|
| 78 |
+
console.log("Sorry folks, the style prompt was cut to:", limitedStylePrompt)
|
| 79 |
}
|
| 80 |
|
| 81 |
// new experimental prompt: let's drop the user prompt!
|
| 82 |
const lightPanelPromptPrefix = preset.imagePrompt("").filter(x => x).join(", ")
|
| 83 |
+
|
| 84 |
+
// this prompt will be used if the LLM generation failed
|
| 85 |
+
const degradedPanelPromptPrefix = [
|
| 86 |
+
...preset.imagePrompt(limitedStylePrompt),
|
| 87 |
+
userStoryPrompt,
|
| 88 |
+
].filter(x => x).join(", ")
|
| 89 |
|
| 90 |
const newPanels: string[] = []
|
| 91 |
const newCaptions: string[] = []
|
src/app/queries/getStory.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const getStory = async ({
|
|
| 27 |
role: "system",
|
| 28 |
content: [
|
| 29 |
`You are a writer specialized in ${preset.llmPrompt}`,
|
| 30 |
-
`Please write detailed drawing instructions and a one-sentence short caption for the ${nbTotalPanels} panels of a new silent story. Please make sure each of the ${nbTotalPanels} panels include info about character gender, age, origin, clothes, colors, location, lights, etc.`,
|
| 31 |
`Give your response as a VALID JSON array like this: \`Array<{ panel: number; instructions: string; caption: string}>\`.`,
|
| 32 |
// `Give your response as Markdown bullet points.`,
|
| 33 |
`Be brief in your ${nbTotalPanels} instructions and captions, don't add your own comments. Be straight to the point, and never reply things like "Sure, I can.." etc. Reply using valid JSON.`
|
|
|
|
| 27 |
role: "system",
|
| 28 |
content: [
|
| 29 |
`You are a writer specialized in ${preset.llmPrompt}`,
|
| 30 |
+
`Please write detailed drawing instructions and a one-sentence short caption for the ${nbTotalPanels} panels of a new silent story. Please make sure each of the ${nbTotalPanels} panels include info about character gender, age, origin, clothes, colors, location, lights, etc. Also include the main theme.`,
|
| 31 |
`Give your response as a VALID JSON array like this: \`Array<{ panel: number; instructions: string; caption: string}>\`.`,
|
| 32 |
// `Give your response as Markdown bullet points.`,
|
| 33 |
`Be brief in your ${nbTotalPanels} instructions and captions, don't add your own comments. Be straight to the point, and never reply things like "Sure, I can.." etc. Reply using valid JSON.`
|