Update app.py
Browse files141 unmodified lines142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174141 unmodified linesdef extract_json_from_codeagent_output(raw_output):try:# First try direct JSON parse if output is cleanif isinstance(raw_output, str) and raw_output.strip().startswith('{'):return json.loads(raw_output)# Look for complete code block patterncode_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 patternif '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 structurejson_match = re.search(r'\{.*\}', raw_output, re.DOTALL)if json_match:return json.loads(json_match.group(0))except Exception as e:print(f"JSON parsing failed: {str(e)}")return Nonedef analyze_data(csv_file, additional_notes=""):try:start_time = time.time()141 unmodified lines142143144145146147148149150151152153154155156157158159160161162163164165166167168169141 unmodified linesdef extract_json_from_codeagent_output(raw_output):import json, ast, retry:# First look for json.dumps inside a code blockcode_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 blockfallback_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: {e}")return Nonedef analyze_data(csv_file, additional_notes=""):try:start_time = time.time()
app.py+17-22