manikantachary18 commited on
Commit
ea7b4ce
·
verified ·
1 Parent(s): f4425cf

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()

Files changed (1) hide show
  1. utils.pyfile +6 -0
utils.pyfile ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ def get_numeric_columns(df):
2
+ return df.select_dtypes(include='number').columns.tolist()
3
+
4
+ def get_all_columns(df):
5
+ return df.columns.tolist()
6
+