콘텐츠로 이동

데이터 분석 대시보드

필요한 모듈 설치하기

!pip install openai
!pip install gradio

Gradio 데이터 분석 템플릿

import gradio as gr
import plotly.express as px
import pandas as pd
import numpy as np

def create_dashboard(data_type, chart_type):
    # 샘플 데이터 생성
    if data_type == "Sales":
        df = pd.DataFrame({
            'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
            'Sales': np.random.randint(1000, 5000, 5),
            'Profit': np.random.randint(100, 800, 5)
        })
    else:
        df = pd.DataFrame({
            'Product': ['A', 'B', 'C', 'D'],
            'Users': np.random.randint(100, 1000, 4)
        })

    if chart_type == "Bar":
        fig = px.bar(df, x=df.columns[0], y=df.columns[1])
    else:
        fig = px.line(df, x=df.columns[0], y=df.columns[1])

    return fig, df

with gr.Blocks(theme=gr.themes.Glass()) as demo:
    gr.Markdown("# 📊 Business Analytics Dashboard")

    with gr.Tabs():
        with gr.TabItem("📈 Charts"):
            with gr.Row():
                data_type = gr.Radio(
                    choices=["Sales", "Users"],
                    value="Sales",
                    label="Data Type"
                )
                chart_type = gr.Radio(
                    choices=["Bar", "Line"],
                    value="Bar",
                    label="Chart Type"
                )

            plot = gr.Plot()

        with gr.TabItem("📋 Data Table"):
            data_table = gr.Dataframe()

    # 자동 업데이트
    for component in [data_type, chart_type]:
        component.change(
            create_dashboard,
            inputs=[data_type, chart_type],
            outputs=[plot, data_table]
        )

demo.launch()