Update app.py
Browse files141 unmodified lines142143144145145146147148149150151152153154155156157149150158159152153154160156157161162163164165166167168141 unmodified lines
def extract_json_from_codeagent_output(raw_output): try: # Try to extract just the json.dumps(...) output if the model followed instructions # 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) # Attempt to load the inner Python dict parsed_dict = eval(json_string) # Safe-ish since it’s model-generated parsed_dict = eval(json_string) return parsed_dict else: # As fallback, try loading the whole string as JSON return json.loads(raw_output) except Exception as e: print(f"[Error] Failed to parse agent output as JSON: {e}") return None print(f"[Fallback 2] Failed to parse json.dumps output: {e}")
print("[Error] Final fallback — unable to parse agent output.") return None
def analyze_data(csv_file, additional_notes=""):app.py+16-8