rameshmoorthy commited on
Commit
a899a25
1 Parent(s): c615795

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -47
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
- # 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
- 'html',
84
- #gr.HTML(label="Data Profile Report", html_content=download_html),
85
- #gr.Button(value="Download Report", type="submit") # Optional: Replace button within HTML if needed
86
- ),
87
- title="Excel sheet Profiling Report",
88
- live=True,
89
- )
90
- # with gr.Blocks() as cluster:
91
- # with gr.Row():
92
- # gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
93
- # gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")]
94
- # btn=gr.Button(label="Download Report")
95
- # with gr.Row():
96
- # gr.Button(value="Download Report", type="submit")
 
 
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()