Spaces:
Running
Running
File size: 2,868 Bytes
0cb60c7 67f471c 9a72b36 0cb60c7 c9d2489 67f471c c9d2489 0cb60c7 9a72b36 830b865 acc4e78 9a72b36 acc4e78 9a72b36 acc4e78 9a72b36 acc4e78 9a72b36 acc4e78 9a72b36 acc4e78 9a72b36 830b865 9a72b36 830b865 0cb60c7 830b865 0cb60c7 06105cd 0cb60c7 9138597 0cb60c7 06105cd 0cb60c7 c9d2489 9a72b36 1fdc206 acc4e78 1fdc206 06105cd 0cb60c7 06105cd 0cb60c7 9138597 06105cd 0cb60c7 9a72b36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
import gradio as gr
import pandas as pd
import sweetviz as sv
import tempfile
import os
import re
class DataAnalyzer:
def __init__(self):
self.temp_dir = tempfile.mkdtemp()
def generate_sweetviz_report(self, df):
report = sv.analyze(df)
report_path = os.path.join(self.temp_dir, "report.html")
report.show_html(report_path, open_browser=False)
with open(report_path, 'r', encoding='utf-8') as f:
html_content = f.read()
# Remove Sweetviz logo and header
html_content = re.sub(r'<div class="header">.*?</div>', '', html_content, flags=re.DOTALL)
html_content = re.sub(r'<div class="logo">.*?</div>', '', html_content, flags=re.DOTALL)
html_content = re.sub(r'<div class="nav-logo">.*?</div>', '', html_content, flags=re.DOTALL)
# Additional CSS to hide unwanted elements and improve layout
custom_css = """
<style>
.header, .logo, .nav-logo {
display: none !important;
}
.container {
width: 100% !important;
max-width: none !important;
padding: 0 !important;
margin-top: 0 !important;
}
.nav {
padding-top: 0 !important;
}
.content {
padding-top: 0 !important;
}
.tab-content {
margin-top: 0 !important;
}
</style>
"""
# Insert custom CSS before closing head tag
html_content = html_content.replace('</head>', f'{custom_css}</head>')
# Clean up
os.remove(report_path)
return html_content
def create_interface():
analyzer = DataAnalyzer()
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# Data Analysis Dashboard")
file_input = gr.File(label="Upload CSV")
report_html = gr.HTML()
def process_file(file):
if file is None:
return None
try:
df = pd.read_csv(file.name)
report = analyzer.generate_sweetviz_report(df)
# Wrap report in container with fixed height
report_with_style = f"""
<div style="height: 800px; overflow: auto; padding: 0;">
{report}
</div>
"""
return report_with_style
except Exception as e:
return f"Error generating report: {str(e)}"
file_input.change(
fn=process_file,
inputs=[file_input],
outputs=[report_html]
)
return demo
if __name__ == "__main__":
demo = create_interface()
demo.launch(show_error=True) |