File size: 1,383 Bytes
f6a9785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()