File size: 1,427 Bytes
95be363
 
 
 
fe1c11d
95be363
fe1c11d
 
95be363
fe1c11d
95be363
 
fe1c11d
 
 
 
 
 
 
 
 
 
 
 
 
a7b4840
 
 
 
 
 
 
 
 
 
 
41ab293
fe1c11d
 
95be363
 
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
40
41
42
import streamlit as st
import pandas as pd
from ydata_profiling import ProfileReport

st.set_page_config(page_title="Dynamic Data Profiling", layout="wide", page_icon="📊")

st.title("Dynamic Data Profiling with ydata-profiling")
st.write("Upload your CSV file and get a complete interactive profiling report!")

uploaded_file = st.file_uploader("Upload a CSV file", type="csv")

if uploaded_file is not None:
    try:
        # Read CSV into DataFrame
        df = pd.read_csv(uploaded_file)
        st.success("File uploaded successfully!")
        
        # Generate the profile report
        with st.spinner("Generating profile report..."):
            profile = ProfileReport(df, title="Profiling Report", explorative=True)
            # Convert report to HTML
            report_html = profile.to_html()

        # Show the report in an iframe
        st.components.v1.html(report_html, height=1200, scrolling=True)

        # Provide a download button for the HTML
        st.write("### Download the Profiling Report")
        # Convert HTML string to bytes
        report_bytes = report_html.encode('utf-8')
        st.download_button(
            label="Download HTML",
            data=report_bytes,
            file_name="profiling_report.html",
            mime="text/html"
        )
        
    except Exception as e:
        st.error(f"An error occurred: {e}")
else:
    st.info("Awaiting CSV file upload.")