Update app.py
Browse files
app.py
CHANGED
|
@@ -4,83 +4,48 @@ import gradio as gr
|
|
| 4 |
from pydantic_settings import BaseSettings
|
| 5 |
from tempfile import NamedTemporaryFile
|
| 6 |
import sweetviz as sv
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
# if type == "pandas profiling":
|
| 10 |
-
# return ydata_profiling.ProfileReport(df).to_html()
|
| 11 |
-
|
| 12 |
-
# elif type == "sweetviz":
|
| 13 |
-
# return sv.analyze(df).show_html(open_browser=True,
|
| 14 |
-
# layout='widescreen',
|
| 15 |
-
# scale=None)
|
| 16 |
-
|
| 17 |
-
# # Custom HTML template for styling the report output
|
| 18 |
-
# custom_html = """
|
| 19 |
-
# <!DOCTYPE html>
|
| 20 |
-
# <html>
|
| 21 |
-
# <head>
|
| 22 |
-
# <title>Data Profile Report</title>
|
| 23 |
-
# <style>
|
| 24 |
-
# body {
|
| 25 |
-
# font-family: Arial, sans-serif;
|
| 26 |
-
# margin: 0;
|
| 27 |
-
# padding: 20px;
|
| 28 |
-
# }
|
| 29 |
-
# .container {
|
| 30 |
-
# width: 80%;
|
| 31 |
-
# margin: auto;
|
| 32 |
-
# }
|
| 33 |
-
# </style>
|
| 34 |
-
# </head>
|
| 35 |
-
# <body>
|
| 36 |
-
# <div class="container">
|
| 37 |
-
# {content}
|
| 38 |
-
# </div>
|
| 39 |
-
# </body>
|
| 40 |
-
# </html>
|
| 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 |
-
html_report =ydata_profiling.ProfileReport(df).to_html()
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 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.Column():
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file")
|
| 80 |
-
type=gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")
|
| 81 |
btn=gr.Button(value="Download Report")
|
| 82 |
-
|
| 83 |
with gr.Row():
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
cluster.launch()
|
|
|
|
| 4 |
from pydantic_settings import BaseSettings
|
| 5 |
from tempfile import NamedTemporaryFile
|
| 6 |
import sweetviz as sv
|
| 7 |
+
from dataprep.datasets import load_dataset
|
| 8 |
+
from dataprep.eda import create_report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def generate_report(file, type):
|
| 11 |
df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
pandas_html_report =ydata_profiling.ProfileReport(df).to_html()
|
| 14 |
+
temp_file1 = NamedTemporaryFile(delete=False, suffix=".html")
|
| 15 |
+
temp_file1.write(pandas_html_report.encode('utf-8'))
|
| 16 |
+
temp_file1.close()
|
| 17 |
+
|
| 18 |
|
| 19 |
+
dataprep_report = create_report(df)
|
| 20 |
+
temp_file2 = NamedTemporaryFile(delete=False, suffix=".html")
|
| 21 |
+
temp_file2.write(dataprep_report.encode('utf-8'))
|
| 22 |
+
temp_file2.close()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
|
| 26 |
+
sweetviz_report = sv.analyze(df)
|
| 27 |
+
temp_file3 = NamedTemporaryFile(delete=False, suffix=".html")
|
| 28 |
+
temp_file3.write(sweetviz_report.encode('utf-8'))
|
| 29 |
+
temp_file3.close()
|
| 30 |
+
|
| 31 |
+
return temp_file1.name ,temp_file2.name ,temp_file3.nam
|
| 32 |
+
|
| 33 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
with gr.Blocks() as cluster:
|
| 35 |
with gr.Column():
|
| 36 |
|
| 37 |
with gr.Row():
|
| 38 |
file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file")
|
|
|
|
| 39 |
btn=gr.Button(value="Download Report")
|
| 40 |
+
|
| 41 |
with gr.Row():
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">PANDAS REPORT</h1>""")
|
| 45 |
+
out1=gr.File(label="Download CSV")
|
| 46 |
+
gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">DATAPREP REPORT</h1>""")
|
| 47 |
+
out2=gr.File(label="Download CSV")
|
| 48 |
+
gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">SWEETVIZ REPORT</h1>""")
|
| 49 |
+
out3=gr.File(label="Download CSV")
|
| 50 |
+
btn.click(generate_report,inputs=[file,type],outputs=[out1,out2,out3])
|
| 51 |
cluster.launch()
|