Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,54 +44,41 @@ import sweetviz as sv
|
|
| 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 |
-
|
| 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 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
cluster.launch()
|
|
|
|
| 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 |
html_report =ydata_profiling.ProfileReport(df).to_html()
|
| 49 |
+
|
| 50 |
+
temp_file = NamedTemporaryFile(delete=False, suffix=".html")
|
| 51 |
+
temp_file.write(html_content.encode('utf-8'))
|
| 52 |
+
temp_file.close()
|
| 53 |
+
return temp_file.name ,html_report
|
| 54 |
|
| 55 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# cluster = gr.Interface(
|
| 58 |
+
# fn=generate_report,
|
| 59 |
+
# inputs=[gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
|
| 60 |
+
# gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")],
|
| 61 |
+
# css="""
|
| 62 |
+
# # Output container styling for better visual presentation (optional)
|
| 63 |
+
# .output-container {
|
| 64 |
+
# padding: 10px;
|
| 65 |
+
# }
|
| 66 |
+
# """,
|
| 67 |
+
# layout=gr.Column(
|
| 68 |
+
# 'html',
|
| 69 |
+
# #gr.HTML(label="Data Profile Report", html_content=download_html),
|
| 70 |
+
# #gr.Button(value="Download Report", type="submit") # Optional: Replace button within HTML if needed
|
| 71 |
+
# ),
|
| 72 |
+
# title="Excel sheet Profiling Report",
|
| 73 |
+
# live=True,
|
| 74 |
+
# )
|
| 75 |
+
with gr.Blocks() as cluster:
|
| 76 |
+
with gr.Row():
|
| 77 |
+
file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
|
| 78 |
+
type=gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")]
|
| 79 |
+
btn=gr.Button(label="Download Report")
|
| 80 |
+
dwn=gr.File(label="Download CSV"),
|
| 81 |
+
with gr.Row():
|
| 82 |
+
out=gr.HTML()
|
| 83 |
+
btn.click(generate_report,inputs=[file,type],outputs=[dwn,out])
|
| 84 |
cluster.launch()
|