Update app.py
Browse files
app.py
CHANGED
|
@@ -111,17 +111,10 @@ 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(
|
| 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*\)",
|
|
@@ -151,6 +144,7 @@ def extract_json_from_codeagent_output(raw_output):
|
|
| 151 |
|
| 152 |
|
| 153 |
|
|
|
|
| 154 |
import pandas as pd
|
| 155 |
import tempfile
|
| 156 |
|
|
@@ -217,7 +211,7 @@ def analyze_data(csv_file, additional_notes=""):
|
|
| 217 |
""", additional_args={"additional_notes": additional_notes, "source_file": cleaned_csv_path})
|
| 218 |
|
| 219 |
|
| 220 |
-
|
| 221 |
|
| 222 |
# Parse output
|
| 223 |
parsed_result = extract_json_from_codeagent_output(raw_output) or {
|
|
|
|
| 111 |
except json.JSONDecodeError:
|
| 112 |
pass # fallback to code block extraction
|
| 113 |
|
| 114 |
+
# Case 3: Extract code blocks and search for JSON-like structures
|
| 115 |
+
code_blocks = re.findall(r"```(?:json|py|python)?\n([\s\S]*?)```", 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*\)",
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
+
|
| 148 |
import pandas as pd
|
| 149 |
import tempfile
|
| 150 |
|
|
|
|
| 211 |
""", additional_args={"additional_notes": additional_notes, "source_file": cleaned_csv_path})
|
| 212 |
|
| 213 |
|
| 214 |
+
print(f"Raw output: {raw_output[:1000]}") # To print first 1000 chars
|
| 215 |
|
| 216 |
# Parse output
|
| 217 |
parsed_result = extract_json_from_codeagent_output(raw_output) or {
|