Commit
•
b9cae72
1
Parent(s):
1fb4531
Update app.py
Browse files
app.py
CHANGED
@@ -41,24 +41,50 @@ body {
|
|
41 |
"""
|
42 |
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
cluster = gr.Interface(
|
54 |
-
generate_report,
|
55 |
-
[gr.File(file_types=['.csv','.xlsx'], label="Upload a CSV or Excel file"),
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
title="Excel sheet Profiling Report",
|
59 |
live=True,
|
60 |
)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
demo.launch(share=True)
|
|
|
41 |
"""
|
42 |
|
43 |
|
44 |
+
|
45 |
+
def generate_report(file, type):
|
46 |
+
df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
|
47 |
+
if type == "pandas profiling":
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
html_report =ydata_profiling.ProfileReport(df).to_html()
|
52 |
+
|
53 |
+
# Add JavaScript code for download functionality
|
54 |
+
download_html = f"""
|
55 |
+
<script>
|
56 |
+
function downloadReport() {{
|
57 |
+
var reportContent = document.getElementById("output").innerHTML;
|
58 |
+
var filename = "report.html";
|
59 |
+
var blob = new Blob([reportContent], {{type: "text/html"}});
|
60 |
+
var link = document.createElement("a");
|
61 |
+
link.href = URL.createObjectURL(blob);
|
62 |
+
link.download = filename;
|
63 |
+
link.click();
|
64 |
+
}}
|
65 |
+
</script>
|
66 |
+
<button onclick="downloadReport()">Download Report</button>
|
67 |
+
{html_report}
|
68 |
+
"""
|
69 |
+
|
70 |
+
return download_html
|
71 |
|
72 |
cluster = gr.Interface(
|
73 |
+
fn=generate_report,
|
74 |
+
inputs=[gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
|
75 |
+
gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")],
|
76 |
+
css="""
|
77 |
+
# Output container styling for better visual presentation (optional)
|
78 |
+
.output-container {
|
79 |
+
padding: 10px;
|
80 |
+
}
|
81 |
+
""",
|
82 |
+
layout=gr.Column(
|
83 |
+
gr.HTML(label="Data Profile Report", html_content=download_html),
|
84 |
+
gr.Button(value="Download Report", type="submit") # Optional: Replace button within HTML if needed
|
85 |
+
),
|
86 |
title="Excel sheet Profiling Report",
|
87 |
live=True,
|
88 |
)
|
89 |
|
90 |
+
cluster.launch()
|
|
|
|