File size: 1,198 Bytes
5fa9951
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()