import pandas as pd import sweetviz as sv from tools.dataframe import get_dataframe_summary from typing import Tuple, Dict import os import tempfile def explain_data(data_raw, n_sample= 10) -> str: """ Tool: explain_data Description: Provides an extensive, narrative summary of a DataFrame including its shape, column types, missing value percentages, unique counts, sample rows, and (if not skipped) descriptive stats/info. Parameters: data_raw (dict): Raw data. n_sample (int, default=30): Number of rows to display. skip_stats (bool, default=False): If True, omit descriptive stats/info. LLM Guidance: Use when a detailed, human-readable explanation is needed—i.e., a full overview is preferred over a concise numerical summary. Returns: str: Detailed DataFrame summary. """ print(" * Tool: explain_data") import pandas as pd result = get_dataframe_summary( pd.DataFrame(data_raw), n_sample=10, skip_stats=False ) return result def generate_sweetviz_report( data_raw: dict, target: str = None, report_name: str = "Report.html", report_directory: str = None, open_browser: bool = False, ) -> Tuple[str, Dict]: df = pd.DataFrame(data_raw) analysis = sv.analyze(df, target_feat=target) if report_directory is None: report_directory = tempfile.mkdtemp() report_path = os.path.join(report_directory, report_name) analysis.show_html(filepath=report_path, open_browser=open_browser) return ( f"Press on the download report button at the bottom", {"report_path": report_path}, )