Update app.py
Browse files139 unmodified lines14014114214314414514614714514614814915014814915015115215115415215315415515615715815916016116216316416516616716816916017017117217317427 unmodified lines20220320419419520520620720819820921021121242 unmodified lines255256257247258259260261262263264265266139 unmodified lines ])
2. **Improve the JSON Parsing Function**:```pythondef extract_json_from_codeagent_output(raw_output): try: # First try direct JSON parse if isinstance(raw_output, str): # First try direct JSON parse if output is clean if isinstance(raw_output, str) and raw_output.strip().startswith('{'): return json.loads(raw_output) # If that fails, look for the json.dumps pattern match = 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 string # 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)) except Exception as e: print(f"JSON parsing error: {e}") print(f"JSON parsing failed: {str(e)}") return None
def analyze_data(csv_file, additional_notes=""):27 unmodified linesYou are a helpful data analysis agent. Please follow these very strict instructions and formatting:
1. Load the data from the provided `source_file`.2. Detect numeric and categorical columns.3. Generate at least 5 visualizations and 5 insights.2. FIRST analyze the data structure (column names and types)3. THEN generate visualizations using EXISTING columns with least 5 visualizations and 5 insights.4. Save all plots to `./figures/` as PNGs using matplotlib or seaborn.5. DO NOT use open() or print() statements.6. Always wrap code in markdown code blocks like this:6. FINALLY return ONLY this exact format:
```pyimport json42 unmodified lines wandb.log({os.path.basename(viz): wandb.Image(viz)})
run.finish()
print("DEBUG - Raw agent output:", analysis_result[:500] + "...") print("Columns in data:", df_global.columns.tolist()) print("Data types:", df_global.dtypes) with open("agent_output.txt", "w") as f: f.write(str(analysis_result)) # Parse the agent output parsed_result = extract_json_from_codeagent_output(analysis_result) print(f"DEBUG - Parsed result: {parsed_result}") # Debug outputapp.py+29-13