Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import plotly.express as px | |
| def process_data(file): | |
| if file is None: | |
| return "File upload kijiye", None, None | |
| # Data Load | |
| df = pd.read_csv(file.name) | |
| # 1. Basic Info | |
| info = f"Dataset mein **{df.shape[0]}** rows aur **{df.shape[1]}** columns hain." | |
| # 2. Stats Table | |
| stats = df.describe().reset_index() | |
| # 3. Automatic Chart (Numeric data ke liye) | |
| num_cols = df.select_dtypes(include=['number']).columns.tolist() | |
| if len(num_cols) >= 2: | |
| fig = px.scatter(df, x=num_cols[0], y=num_cols[1], title=f"{num_cols[0]} vs {num_cols[1]}") | |
| else: | |
| fig = px.bar(df, title="Data Preview") | |
| return info, stats, fig | |
| # Gradio UI | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# ๐ Data Analyst AI") | |
| file_input = gr.File(label="CSV File Upload Karein") | |
| btn = gr.Button("Analyze Now", variant="primary") | |
| out_text = gr.Markdown() | |
| out_table = gr.DataFrame(label="Statistical Summary") | |
| out_plot = gr.Plot(label="Data Visualization") | |
| btn.click(process_data, inputs=[file_input], outputs=[out_text, out_table, out_plot]) | |
| demo.launch() |