Skip to content

Commit 442fd26

Browse files
committed
update streamlit nodes/flow
1 parent 516a527 commit 442fd26

File tree

2 files changed

+16
-71
lines changed

2 files changed

+16
-71
lines changed
Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
from pocketflow import Flow
2-
from nodes import InitialInputNode, ProcessDataNode, PrepareFinalResultNode
2+
from nodes import GenerateImageNode
33

4-
def create_initial_processing_flow():
5-
"""Creates a flow for the initial data processing stage."""
6-
initial_input_node = InitialInputNode()
7-
process_data_node = ProcessDataNode()
4+
def create_generation_flow():
5+
"""Creates a flow for image generation (initial or regeneration)."""
6+
generate_image_node = GenerateImageNode()
7+
return Flow(start=generate_image_node)
88

9-
# Define transitions: Input -> Process
10-
initial_input_node >> process_data_node
119

12-
# Create the Flow, starting with the input node
13-
flow = Flow(start=initial_input_node)
14-
print("Initial processing flow created.")
15-
return flow
16-
17-
def create_finalization_flow():
18-
"""Creates a flow to finalize the result after approval."""
19-
prepare_final_result_node = PrepareFinalResultNode()
20-
21-
# This flow only has one node
22-
flow = Flow(start=prepare_final_result_node)
23-
print("Finalization flow created.")
24-
return flow
Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,17 @@
11
from 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

Comments
 (0)