Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| from data_loader import load_data | |
| from visualizer import create_plot | |
| from utils import get_numeric_columns, get_all_columns | |
| df_global = None # Used to persist the DataFrame | |
| def process_file(file): | |
| global df_global | |
| df_global = load_data(file) | |
| return ( | |
| df_global.head(), | |
| get_all_columns(df_global), | |
| get_numeric_columns(df_global) | |
| ) | |
| def update_plot(chart_type, x_col, y_col): | |
| if df_global is not None: | |
| fig = create_plot(df_global, chart_type, x_col, y_col) | |
| return fig | |
| return None | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π Power BI-style Data Visualization App") | |
| with gr.Row(): | |
| file_input = gr.File(label="Upload your data file (.csv, .xlsx, .json)") | |
| dataframe_output = gr.Dataframe(label="Data Preview", interactive=False) | |
| with gr.Row(): | |
| chart_type = gr.Dropdown(["Bar Chart", "Line Chart", "Scatter Plot", "Pie Chart", "Box Plot"], label="Chart Type") | |
| x_col = gr.Dropdown(label="X-axis Column") | |
| y_col = gr.Dropdown(label="Y-axis Column") | |
| plot_output = gr.Plot(label="Generated Chart") | |
| file_input.change(fn=process_file, inputs=file_input, outputs=[dataframe_output, x_col, y_col]) | |
| gr.Button("Generate Chart").click(fn=update_plot, inputs=[chart_type, x_col, y_col], outputs=plot_output) | |
| demo.launch() | |