11from pocketflow import Node
2- from utils .process_task import process_task
2+ from utils .generate_image import generate_image
33
4- class InitialInputNode (Node ):
5- """Reads the initial task input from shared_data."""
4+ class GenerateImageNode (Node ):
5+ """Generates image from text prompt using OpenAI API."""
6+
67 def prep (self , shared ):
7- print ("InitialInputNode: Prep" )
8- return shared .get ("task_input" , "Default Task Input" )
8+ return shared .get ("task_input" , "" )
99
10- def exec (self , prep_res ):
11- print (f"InitialInputNode: Executing with input: '{ prep_res [:50 ]} ...'" )
12- # No real computation needed here, just passing the input along
13- return prep_res
10+ def exec (self , prompt ):
11+ return generate_image (prompt )
1412
1513 def post (self , shared , prep_res , exec_res ):
16- # Ensure the input used is stored, although it might already be there
17- shared ["input_used_by_process" ] = exec_res
18- print (f"InitialInputNode: Post - Stored input '{ exec_res [:50 ]} ...' in shared_data." )
19- return "default" # Proceed to next node in the flow
20-
21- class ProcessDataNode (Node ):
22- """Processes the data using the utility function."""
23- def prep (self , shared ):
24- task_input = shared .get ("input_used_by_process" , "No input found" )
25- print (f"ProcessDataNode: Prep - Input: '{ task_input [:50 ]} ...'" )
26- return task_input
27-
28- def exec (self , prep_res ):
29- print ("ProcessDataNode: Exec - Calling process_task utility" )
30- # Call the actual processing logic
31- processed_output = process_task (prep_res )
32- return processed_output
33-
34- def post (self , shared , prep_res , exec_res ):
35- # Store the result for review
36- shared ["processed_output" ] = exec_res
37- print (f"ProcessDataNode: Post - Stored processed output: '{ str (exec_res )[:50 ]} ...'" )
38- # This node ends the initial processing subflow
39- return None
40-
41- class PrepareFinalResultNode (Node ):
42- """Takes the approved processed output and sets it as the final result."""
43- def prep (self , shared ):
44- approved_output = shared .get ("processed_output" , "No processed output found" )
45- print (f"PrepareFinalResultNode: Prep - Approved output: '{ str (approved_output )[:50 ]} ...'" )
46- return approved_output
47-
48- def exec (self , prep_res ):
49- print ("PrepareFinalResultNode: Exec - Finalizing result." )
50- # Could potentially do final formatting here if needed
51- return prep_res
52-
53- def post (self , shared , prep_res , exec_res ):
54- shared ["final_result" ] = exec_res
55- print (f"PrepareFinalResultNode: Post - Stored final result: '{ str (exec_res )[:50 ]} ...'" )
56- # This node ends the finalization subflow
57- return None
14+ shared ["input_used_by_process" ] = prep_res
15+ shared ["generated_image" ] = exec_res
16+ shared ["stage" ] = "user_feedback"
17+ return "default"
0 commit comments