import pandas as pd | |
import ydata_profiling | |
import gradio as gr | |
from pydantic_settings import BaseSettings | |
from tempfile import NamedTemporaryFile | |
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() | |
temp_file = NamedTemporaryFile(delete=False, suffix=".html") | |
temp_file.write(html_content.encode('utf-8')) | |
temp_file.close() | |
return temp_file.name ,html_report | |
# 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.Column(): | |
with gr.Row(): | |
file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file") | |
type=gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data") | |
btn=gr.Button(value="Download Report") | |
dwn=gr.File(label="Download CSV") | |
with gr.Row(): | |
out=gr.HTML() | |
btn.click(generate_report,inputs=[file,type],outputs=[dwn,out]) | |
cluster.launch() | |