Update app.py
Browse files141 unmodified lines142143144145146147146147148149150151152153154155156157158159160161162163164165166148149150151152153154155156157158159160161168162163164165166167168169141 unmodified lines
def extract_json_from_codeagent_output(raw_output): import json, ast, re
try: # First try direct JSON parse if output is clean if isinstance(raw_output, str) and raw_output.strip().startswith('{'): return json.loads(raw_output) # Look for complete code block pattern code_block_pattern = r'```(?:py|python)?\n(.*?)\n```' matches = re.findall(code_block_pattern, raw_output, re.DOTALL) if matches: for match in matches: # Find the json.dumps pattern if 'json.dumps' in match: dict_part = re.search(r'result\s*=\s*({.*?})\s*\n', match, re.DOTALL) if dict_part: return ast.literal_eval(dict_part.group(1)) # Final fallback - find any JSON structure json_match = re.search(r'\{.*\}', raw_output, re.DOTALL) if json_match: return json.loads(json_match.group(0)) # First look for json.dumps inside a code block code_blocks = re.findall(r"```(?:py|python)?\n(.*?)```", raw_output, re.DOTALL) for block in code_blocks: json_match = re.search(r"json\.dumps\s*\(\s*(\{.*?\})\s*\)", block, re.DOTALL) if json_match: cleaned = json_match.group(1) return json.loads(cleaned)
# Final fallback - extract any JSON-like block fallback_match = re.search(r"(\{[\s\S]+\})", raw_output) if fallback_match: return json.loads(fallback_match.group(1))
except Exception as e: print(f"JSON parsing failed: {str(e)}") print(f"JSON parsing failed: {e}") return None
def analyze_data(csv_file, additional_notes=""): try: start_time = time.time()app.py+17-22