File size: 2,905 Bytes
ca86eea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gradio as gr

from predictive_ml_workbench.service import PredictiveMLWorkbenchService


service = PredictiveMLWorkbenchService()


def run_workbench(file_obj, workflow, target_column, test_size, cv_folds, max_clusters):
    file_path = getattr(file_obj, "name", file_obj)
    return service.run(
        csv_path=file_path,
        workflow=workflow,
        target_column=target_column,
        test_size=float(test_size),
        cv_folds=int(cv_folds),
        max_clusters=int(max_clusters),
    )


with gr.Blocks(
    title="Predictive ML Workbench",
    theme=gr.themes.Soft(primary_hue="green", secondary_hue="blue"),
) as demo:
    gr.Markdown(
        """
        # Predictive ML Workbench
        Upload a CSV dataset and run end-to-end machine learning workflows for regression,
        classification, clustering, dimensionality reduction, preprocessing, model selection,
        and evaluation.
        """
    )

    with gr.Accordion("What this project covers", open=False):
        gr.Markdown(
            """
            - Regression
            - Classification
            - Clustering
            - Dimensionality reduction
            - Preprocessing with numeric and categorical pipelines
            - Model selection with cross-validation
            - Evaluation with workflow-specific metrics and plots
            """
        )

    dataset_input = gr.File(label="CSV Dataset", file_types=[".csv"])

    with gr.Row():
        workflow_input = gr.Dropdown(
            choices=["Classification", "Regression", "Clustering", "Dimensionality Reduction"],
            value="Classification",
            label="Workflow",
        )
        target_input = gr.Textbox(
            label="Target Column",
            placeholder="Required for regression/classification; optional otherwise",
        )

    with gr.Row():
        test_size_input = gr.Slider(0.1, 0.4, value=0.2, step=0.05, label="Test Split")
        cv_input = gr.Slider(2, 5, value=3, step=1, label="CV Folds")
        cluster_input = gr.Slider(3, 8, value=6, step=1, label="Max Clusters")

    run_button = gr.Button("Run Workflow", variant="primary")

    model_output = gr.Textbox(label="Selected Model / Method", lines=2)
    metrics_output = gr.Textbox(label="Metrics", lines=10)
    preview_output = gr.Textbox(label="Data Preview", lines=10)
    plot_output = gr.Plot(label="Visualization")
    status_output = gr.Textbox(label="Status", lines=3)

    run_button.click(
        fn=run_workbench,
        inputs=[
            dataset_input,
            workflow_input,
            target_input,
            test_size_input,
            cv_input,
            cluster_input,
        ],
        outputs=[
            model_output,
            metrics_output,
            preview_output,
            plot_output,
            status_output,
        ],
    )


if __name__ == "__main__":
    demo.launch()