Update app.py
Browse files141 unmodified lines142143144145146147148149150151152153154155156157158159160161162163164165166167168169170141 unmodified linesdef extract_json_from_codeagent_output(raw_output):try:# Strip everything before the first `{`json_start = raw_output.find('{')if json_start != -1:json_str = raw_output[json_start:]return json.loads(json_str)except Exception as e:print(f"[Fallback 1] Failed to parse stripped JSON: {e}")try:# Try the json.dumps(...) regex extraction (only if that pattern exists)match = re.search(r'json\.dumps\((.*?)\)\s*$', raw_output, re.DOTALL)if match:json_string = match.group(1)parsed_dict = eval(json_string)return parsed_dictexcept Exception as e:print(f"[Fallback 2] Failed to parse json.dumps output: {e}")print("[Error] Final fallback — unable to parse agent output.")return Nonedef analyze_data(csv_file, additional_notes=""):start_time = time.time()process = psutil.Process(os.getpid())141 unmodified lines142143144145146147148149150151152153154155156157158159160161162163164165141 unmodified linesdef extract_json_from_codeagent_output(raw_output):try:# First try direct JSON parseif isinstance(raw_output, str):return json.loads(raw_output)# If that fails, look for the json.dumps patternmatch = re.search(r'json\.dumps\(({.*?})\)', raw_output, re.DOTALL)if match:return ast.literal_eval(match.group(1))# Final fallback - try to find any JSON in the stringjson_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 error: {e}")return Nonedef analyze_data(csv_file, additional_notes=""):start_time = time.time()process = psutil.Process(os.getpid())
app.py+14-19