Update app.py
Browse files
app.py
CHANGED
|
@@ -435,6 +435,21 @@ def extract_json_from_llm_response(raw_response: str) -> dict:
|
|
| 435 |
logger.error("Sanitized JSON still invalid:\n%s", json_string)
|
| 436 |
raise
|
| 437 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
# Node 1: Logic updating if any issue here
|
| 439 |
def pseudo_generator_node(state: GameState):
|
| 440 |
logger.info("--- Running plan_logic_aligner_node ---")
|
|
@@ -598,7 +613,8 @@ If you find any "Code-Blocks" then,
|
|
| 598 |
image_input = {
|
| 599 |
"type": "image_url",
|
| 600 |
"image_url": {
|
| 601 |
-
"url": f"data:image/png;base64,{image}"
|
|
|
|
| 602 |
}
|
| 603 |
}
|
| 604 |
|
|
|
|
| 435 |
logger.error("Sanitized JSON still invalid:\n%s", json_string)
|
| 436 |
raise
|
| 437 |
|
| 438 |
+
def clean_base64_for_model(raw_b64: str) -> str:
|
| 439 |
+
if not raw_b64:
|
| 440 |
+
return ""
|
| 441 |
+
# Remove prefix if exists
|
| 442 |
+
clean_b64 = re.sub(r"^data:image\/[a-zA-Z]+;base64,", "", raw_b64)
|
| 443 |
+
# Remove spaces/newlines
|
| 444 |
+
clean_b64 = clean_b64.replace("\n", "").replace("\r", "").strip()
|
| 445 |
+
# Validate
|
| 446 |
+
try:
|
| 447 |
+
base64.b64decode(clean_b64)
|
| 448 |
+
except Exception as e:
|
| 449 |
+
logger.error(f"Invalid Base64 passed to model: {e}")
|
| 450 |
+
raise
|
| 451 |
+
return f"data:image/png;base64,{clean_b64}"
|
| 452 |
+
|
| 453 |
# Node 1: Logic updating if any issue here
|
| 454 |
def pseudo_generator_node(state: GameState):
|
| 455 |
logger.info("--- Running plan_logic_aligner_node ---")
|
|
|
|
| 613 |
image_input = {
|
| 614 |
"type": "image_url",
|
| 615 |
"image_url": {
|
| 616 |
+
# "url": f"data:image/png;base64,{image}"
|
| 617 |
+
"url": clean_base64_for_model(image)
|
| 618 |
}
|
| 619 |
}
|
| 620 |
|