Update app.py
Browse files
app.py
CHANGED
|
@@ -111,10 +111,17 @@ def extract_json_from_codeagent_output(raw_output):
|
|
| 111 |
except json.JSONDecodeError:
|
| 112 |
pass # fallback to code block extraction
|
| 113 |
|
| 114 |
-
# Case 3: Extract code blocks
|
| 115 |
code_blocks = re.findall(r"```(?:json|py|python)?\n(.*?)```", raw_output, re.DOTALL)
|
| 116 |
|
| 117 |
for block in code_blocks:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
for pattern in [
|
| 119 |
r"print\(\s*json\.dumps\(\s*(\{[\s\S]*?\})\s*\)\s*\)",
|
| 120 |
r"json\.dumps\(\s*(\{[\s\S]*?\})\s*\)",
|
|
@@ -143,6 +150,7 @@ def extract_json_from_codeagent_output(raw_output):
|
|
| 143 |
return {"error": "Failed to extract structured JSON"}
|
| 144 |
|
| 145 |
|
|
|
|
| 146 |
import pandas as pd
|
| 147 |
import tempfile
|
| 148 |
|
|
|
|
| 111 |
except json.JSONDecodeError:
|
| 112 |
pass # fallback to code block extraction
|
| 113 |
|
| 114 |
+
# Case 3: Extract code blocks with any tag: json, py, python, or untagged
|
| 115 |
code_blocks = re.findall(r"```(?:json|py|python)?\n(.*?)```", raw_output, re.DOTALL)
|
| 116 |
|
| 117 |
for block in code_blocks:
|
| 118 |
+
# Try loading the block directly as JSON first
|
| 119 |
+
try:
|
| 120 |
+
return json.loads(block)
|
| 121 |
+
except json.JSONDecodeError:
|
| 122 |
+
pass # continue with patterns
|
| 123 |
+
|
| 124 |
+
# Then look for common assignment patterns
|
| 125 |
for pattern in [
|
| 126 |
r"print\(\s*json\.dumps\(\s*(\{[\s\S]*?\})\s*\)\s*\)",
|
| 127 |
r"json\.dumps\(\s*(\{[\s\S]*?\})\s*\)",
|
|
|
|
| 150 |
return {"error": "Failed to extract structured JSON"}
|
| 151 |
|
| 152 |
|
| 153 |
+
|
| 154 |
import pandas as pd
|
| 155 |
import tempfile
|
| 156 |
|