diff --git a/frontend/src/NewApp/Pages/GenerateCandidate.tsx b/frontend/src/NewApp/Pages/GenerateCandidate.tsx index b657260..c8b7c13 100644 --- a/frontend/src/NewApp/Pages/GenerateCandidate.tsx +++ b/frontend/src/NewApp/Pages/GenerateCandidate.tsx @@ -53,81 +53,6 @@ const GenerateCandidate = (props: BackstoryElementProps) => { const controllerRef = useRef(null); const backstoryTextRef = useRef(null); - const generateProfile = useCallback((userInfo?: UserInfo, promptText?: string) => { - // Use provided params or current state - const currentUser = userInfo || user; - const currentPrompt = promptText || prompt; - - if (controllerRef.current) { - return; - } - - // Don't generate if we still have blank user data - if (currentUser.username === "[blank]" || currentUser.first_name === "[blank]") { - console.log("Cannot generate profile: user data not ready"); - return; - } - - const imagePrompt = `A photorealistic profile picture of a ${currentUser.age} year old ${currentUser.gender} ${currentUser.ethnicity} person. ${currentPrompt}` - setStatus(`Generating: ${imagePrompt}`); - setProcessing(true); - setCanGenImage(false); - setState(3); - const start = Date.now(); - - controllerRef.current = streamQueryResponse({ - query: { - prompt: imagePrompt, - agent_options: { - username: currentUser.username, - filename: "profile.png" - } - }, - type: "image", - sessionId, - connectionBase, - onComplete: (msg) => { - console.log(msg); - switch (msg.status) { - case "partial": - case "done": - if (msg.status === "done") { - setProcessing(false); - controllerRef.current = null; - setState(0); - setCanGenImage(true); - setShouldGenerateProfile(false); - setUser({ ...user, has_profile: true }); - } - break; - case "error": - console.log(`Error generating persona: ${msg.response} after ${Date.now() - start}`); - setSnack(msg.response || "", "error"); - setProcessing(false); - controllerRef.current = null; - setState(0); - setCanGenImage(true); - setShouldGenerateProfile(false); - break; - default: - const data = JSON.parse(msg.response || ''); - if (msg.status !== "heartbeat") { - console.log(data); - } - if (data.timestamp) { - setTimestamp(data.timestamp); - } else { - setTimestamp(Date.now()) - } - if (data.message) { - setStatus(data.message); - } - break; - } - } - }); - }, [user, prompt, sessionId, setSnack]); - const generatePersona = useCallback((query: Query) => { if (controllerRef.current) { return; @@ -199,7 +124,7 @@ const GenerateCandidate = (props: BackstoryElementProps) => { setStreaming(chunk); } }); - }, [sessionId, setSnack, generateProfile]); + }, [sessionId, setSnack]); const cancelQuery = useCallback(() => { if (controllerRef.current) { @@ -230,7 +155,6 @@ const GenerateCandidate = (props: BackstoryElementProps) => { console.log("useEffect triggered - shouldGenerateProfile:", shouldGenerateProfile, "user:", user.username, user.first_name); if (shouldGenerateProfile && user.username !== "[blank]" && user.first_name !== "[blank]") { console.log("Triggering profile generation with updated user data:", user); - // Call generateProfile directly with current values to avoid closure issues if (controllerRef.current) { console.log("Controller already active, skipping profile generation"); return; @@ -242,6 +166,8 @@ const GenerateCandidate = (props: BackstoryElementProps) => { return; } + const imagePrompt = `A photorealistic profile picture of a ${user.age} year old ${user.gender} ${user.ethnicity} person. ${prompt}` + setStatus(`Generating: ${imagePrompt}`); setProcessing(true); setCanGenImage(false); setState(3); @@ -249,7 +175,7 @@ const GenerateCandidate = (props: BackstoryElementProps) => { controllerRef.current = streamQueryResponse({ query: { - prompt: `A photorealistic profile picture of a ${user.age} year old ${user.gender} ${user.ethnicity} person. ${prompt}`, + prompt: imagePrompt, agent_options: { username: user.username, filename: "profile.png" @@ -269,6 +195,7 @@ const GenerateCandidate = (props: BackstoryElementProps) => { setState(0); setCanGenImage(true); setShouldGenerateProfile(false); + setUser({ ...user, has_profile: true }); } break; case "error": @@ -359,7 +286,7 @@ const GenerateCandidate = (props: BackstoryElementProps) => { { sx={{ m: 1, gap: 1, flexGrow: 1 }} variant="contained" disabled={sessionId === undefined || processing || !canGenImage} - onClick={() => { generateProfile() }}> + onClick={() => { setShouldGenerateProfile(true); }}> Generate Picture