File size: 1,289 Bytes
136b539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import pandas as pd
from sklearn.preprocessing import LabelEncoder, OrdinalEncoder
import io
import numpy as np
import tempfile
import os


# ===========================================================
#        Detailed Data Report using pandas-profiling
# ===========================================================

def generate_profile_report(df):
    """Generate a pandas profiling HTML report and optionally open in a new tab."""
    if df is None or df.empty:
        return None, "⚠️ Please load a valid dataset first."

    try:
        from ydata_profiling import ProfileReport
    except ImportError:
        return None, "❌ Missing dependency: please install it using 'pip install ydata-profiling'."

    try:
        profile = ProfileReport(df, title="πŸ“Š Detailed Data Report", explorative=True)
        output_path = "data_profile_report.html"
        profile.to_file(output_path)

        # Create a clickable HTML link that opens in new tab
        html_link = f"""
        βœ… Report generated successfully! Now Download the report (in HTML format) and open it.<br>
        """
        # Return the file + HTML message
        return output_path, html_link
    except Exception as e:
        return None, f"❌ Failed to generate report: {e}"