Spaces:
Sleeping
Sleeping
# ui/layout.py | |
import gradio as gr | |
from core.config import settings | |
def create_main_layout(): | |
"""Defines and returns the entire Gradio UI structure.""" | |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="indigo"), title=settings.APP_TITLE) as demo: | |
# State object to hold the DataAnalyzer instance | |
state_analyzer = gr.State() | |
# --- Header --- | |
gr.Markdown(f"<h1>{settings.APP_TITLE}</h1>") | |
gr.Markdown("A world-class data discovery platform that provides a complete suite of EDA tools and intelligently unlocks specialized analysis modules for Time-Series, Text, and Clustering.") | |
# --- Input Row --- | |
with gr.Row(): | |
upload_button = gr.File(label="1. Upload Data File (CSV, Excel)", file_types=[".csv", ".xlsx"], scale=3) | |
analyze_button = gr.Button("β¨ Generate Intelligence Report", variant="primary", scale=1) | |
# --- Main Tabs --- | |
with gr.Tabs(): | |
# Tab 1: AI Narrative | |
with gr.Tab("π€ AI-Powered Strategy Report", id="tab_ai"): | |
ai_report_output = gr.Markdown("### Your AI-generated report will appear here after analysis...") | |
# Tab 2: Data Profile | |
with gr.Tab("π Data Profile", id="tab_profile"): | |
with gr.Accordion("Missing Values Report", open=False): | |
profile_missing_df = gr.DataFrame() | |
with gr.Accordion("Numeric Features Summary", open=True): | |
profile_numeric_df = gr.DataFrame() | |
with gr.Accordion("Categorical Features Summary", open=True): | |
profile_categorical_df = gr.DataFrame() | |
# Tab 3: Overview Visuals | |
with gr.Tab("π Overview Visuals", id="tab_overview"): | |
with gr.Row(): | |
plot_types = gr.Plot() | |
plot_missing = gr.Plot() | |
plot_correlation = gr.Plot() | |
# Tab 4: Interactive Explorer | |
with gr.Tab("π¨ Interactive Explorer", id="tab_explorer"): | |
gr.Markdown("### Univariate Analysis") | |
with gr.Row(): | |
dd_hist_col = gr.Dropdown(label="Select Column for Histogram", interactive=True) | |
plot_histogram = gr.Plot() | |
gr.Markdown("### Bivariate Analysis") | |
with gr.Row(): | |
with gr.Column(scale=1): | |
dd_scatter_x = gr.Dropdown(label="X-Axis (Numeric)", interactive=True) | |
dd_scatter_y = gr.Dropdown(label="Y-Axis (Numeric)", interactive=True) | |
dd_scatter_color = gr.Dropdown(label="Color By (Optional)", interactive=True) | |
with gr.Column(scale=2): | |
plot_scatter = gr.Plot() | |
# Tab 5: Time-Series Analysis (Conditional) | |
with gr.Tab("β Time-Series Analysis", id="tab_timeseries", visible=False) as tab_timeseries: | |
# ... layout for time series ... | |
pass # Placeholder for brevity | |
# Tab 6: Text Analysis (Conditional) | |
with gr.Tab("π Text Analysis", id="tab_text", visible=False) as tab_text: | |
# ... layout for text ... | |
pass # Placeholder for brevity | |
# Tab 7: Clustering Analysis (Conditional) | |
with gr.Tab("π§© Clustering (K-Means)", id="tab_cluster", visible=False) as tab_cluster: | |
with gr.Row(): | |
with gr.Column(scale=1): | |
num_clusters = gr.Slider(minimum=2, maximum=10, value=3, step=1, label="Number of Clusters (K)", interactive=True) | |
md_cluster_summary = gr.Markdown() | |
with gr.Column(scale=2): | |
plot_cluster = gr.Plot() | |
plot_elbow = gr.Plot() | |
# Collect all components that need to be updated | |
# This is a bit verbose but necessary for Gradio's output mapping | |
components = { | |
"state_analyzer": state_analyzer, "upload_button": upload_button, "analyze_button": analyze_button, | |
"ai_report_output": ai_report_output, "profile_missing_df": profile_missing_df, | |
"profile_numeric_df": profile_numeric_df, "profile_categorical_df": profile_categorical_df, | |
"plot_types": plot_types, "plot_missing": plot_missing, "plot_correlation": plot_correlation, | |
"dd_hist_col": dd_hist_col, "plot_histogram": plot_histogram, "dd_scatter_x": dd_scatter_x, | |
"dd_scatter_y": dd_scatter_y, "dd_scatter_color": dd_scatter_color, "plot_scatter": plot_scatter, | |
"tab_timeseries": tab_timeseries, "tab_text": tab_text, "tab_cluster": tab_cluster, | |
"num_clusters": num_clusters, "md_cluster_summary": md_cluster_summary, | |
"plot_cluster": plot_cluster, "plot_elbow": plot_elbow, | |
} | |
return demo, components |