|
import pandas as pd |
|
import ydata_profiling |
|
import gradio as gr |
|
from pydantic_settings import BaseSettings |
|
|
|
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 = """ |
|
<!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> |
|
""" |
|
|
|
|
|
profile = gr.Interface( |
|
generate_report, |
|
[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")], |
|
gr.HTML(label="Data profile Report", html_content=custom_html), |
|
title="Excel sheet Profiling Report", |
|
live=True, |
|
) |
|
|
|
cluster = gr.Interface( |
|
generate_report, |
|
[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")], |
|
gr.HTML(label="Data profile Report", html_content=custom_html), |
|
title="Excel sheet Profiling Report", |
|
live=True, |
|
) |
|
|
|
demo = gr.TabbedInterface([cluster, profile], ["Product clustering", "Data Exploration"]) |
|
|
|
demo.launch(share=True) |