Upload app.py
Browse files
app.py
CHANGED
|
@@ -542,6 +542,16 @@ def extract_json(s: str):
|
|
| 542 |
def execute_page_expert(expert_instructions: str, page_num: int):
|
| 543 |
state.add_log(f'👁️ Spawning Page Expert for page **{page_num}**')
|
| 544 |
state.add_analysis(f"👁️ Page Expert searching for {expert_instructions}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
client = openai.OpenAI()
|
| 546 |
|
| 547 |
tools = [
|
|
@@ -937,19 +947,7 @@ def agent_worker(user_question):
|
|
| 937 |
tile_indexes=tile_idxs,
|
| 938 |
page_num=page_num
|
| 939 |
)
|
| 940 |
-
result["high_res_proof_b64"] = base64.b64encode(
|
| 941 |
-
stitched_bytes
|
| 942 |
-
).decode("utf-8")
|
| 943 |
|
| 944 |
-
state.add_log(f'📄 Attaching full-page context for page **{page_num}**')
|
| 945 |
-
state.add_analysis(
|
| 946 |
-
f"📄 Full-page context attached for page `{page_num}`"
|
| 947 |
-
)
|
| 948 |
-
|
| 949 |
-
full_page_img = Image.open(
|
| 950 |
-
io.BytesIO(image_bytes_list[page_num])
|
| 951 |
-
)
|
| 952 |
-
state.add_image(full_page_img)
|
| 953 |
|
| 954 |
tool_responses.append(
|
| 955 |
types.Part.from_function_response(
|
|
@@ -957,6 +955,25 @@ def agent_worker(user_question):
|
|
| 957 |
response={"result": result}
|
| 958 |
)
|
| 959 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
|
| 961 |
state.add_analysis("🧠 Returning tool outputs to planner...")
|
| 962 |
response = chat.send_message(tool_responses)
|
|
|
|
| 542 |
def execute_page_expert(expert_instructions: str, page_num: int):
|
| 543 |
state.add_log(f'👁️ Spawning Page Expert for page **{page_num}**')
|
| 544 |
state.add_analysis(f"👁️ Page Expert searching for {expert_instructions}")
|
| 545 |
+
state.add_log(f'📄 Attaching full-page context for page **{page_num}**')
|
| 546 |
+
state.add_analysis(
|
| 547 |
+
f"📄 Full-page context attached for page `{page_num}`"
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
full_page_img = Image.open(
|
| 551 |
+
io.BytesIO(image_bytes_list[page_num])
|
| 552 |
+
)
|
| 553 |
+
state.add_image(full_page_img)
|
| 554 |
+
|
| 555 |
client = openai.OpenAI()
|
| 556 |
|
| 557 |
tools = [
|
|
|
|
| 947 |
tile_indexes=tile_idxs,
|
| 948 |
page_num=page_num
|
| 949 |
)
|
|
|
|
|
|
|
|
|
|
| 950 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 951 |
|
| 952 |
tool_responses.append(
|
| 953 |
types.Part.from_function_response(
|
|
|
|
| 955 |
response={"result": result}
|
| 956 |
)
|
| 957 |
)
|
| 958 |
+
|
| 959 |
+
# If this tool produced visual proof, ALSO send it as an image part
|
| 960 |
+
if name == "execute_page_expert":
|
| 961 |
+
tile_idxs = result.get("visual_pointers", [])
|
| 962 |
+
page_num = args.get("page_num")
|
| 963 |
+
|
| 964 |
+
if stitched_bytes:
|
| 965 |
+
tool_responses.append(
|
| 966 |
+
types.Part.from_bytes(
|
| 967 |
+
stitched_bytes,
|
| 968 |
+
mime_type="image/png"
|
| 969 |
+
)
|
| 970 |
+
)
|
| 971 |
+
tool_responses.append(
|
| 972 |
+
types.Part.from_bytes(
|
| 973 |
+
image_bytes_list[page_num],
|
| 974 |
+
mime_type="image/png"
|
| 975 |
+
)
|
| 976 |
+
)
|
| 977 |
|
| 978 |
state.add_analysis("🧠 Returning tool outputs to planner...")
|
| 979 |
response = chat.send_message(tool_responses)
|