File size: 2,899 Bytes
0a5d39a 7a75289 0a5d39a 71c9026 c1d9e7e 1065d81 a246aa4 25cd492 a246aa4 1065d81 a246aa4 1065d81 0a5d39a b9cae72 0a5d39a 15a4a02 b9cae72 e8be650 b9cae72 15a4a02 e8be650 b9cae72 |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import pandas as pd
import ydata_profiling
import gradio as gr
from pydantic_settings import BaseSettings
import sweetviz as sv
# def generate_report(file,type):
# df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
# if type == "pandas profiling":
# return ydata_profiling.ProfileReport(df).to_html()
# elif type == "sweetviz":
# return sv.analyze(df).show_html(open_browser=True,
# layout='widescreen',
# scale=None)
# # Custom HTML template for styling the report output
# custom_html = """
# <!DOCTYPE html>
# <html>
# <head>
# <title>Data Profile Report</title>
# <style>
# body {
# font-family: Arial, sans-serif;
# margin: 0;
# padding: 20px;
# }
# .container {
# width: 80%;
# margin: auto;
# }
# </style>
# </head>
# <body>
# <div class="container">
# {content}
# </div>
# </body>
# </html>
# """
def generate_report(file, type):
df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
if type == "pandas profiling":
html_report =ydata_profiling.ProfileReport(df).to_html()
# Add JavaScript code for download functionality
download_html = f"""
<script>
function downloadReport() {{
var reportContent = document.getElementById("output").innerHTML;
var filename = "report.html";
var blob = new Blob([reportContent], {{type: "text/html"}});
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
}}
</script>
<button onclick="downloadReport()">Download Report</button>
{html_report}
"""
return download_html
cluster = gr.Interface(
fn=generate_report,
inputs=[gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")],
css="""
# Output container styling for better visual presentation (optional)
.output-container {
padding: 10px;
}
""",
layout=gr.Column(
'html'
#gr.HTML(label="Data Profile Report", html_content=download_html),
gr.Button(value="Download Report", type="submit") # Optional: Replace button within HTML if needed
),
title="Excel sheet Profiling Report",
live=True,
)
# with gr.Blocks() as cluster:
# with gr.Row():
# gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
# gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")]
# btn=gr.Button(value="Download Report", type="submit")
# with gr.Row():
# gr.Button(value="Download Report", type="submit")
cluster.launch()
|