File size: 1,729 Bytes
cdc04d9 | 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 | import gradio as gr
from ml_tabular.service import TabularMLService
service = TabularMLService()
def train_model(file_obj, target_column, task_type, test_size, random_state):
file_path = getattr(file_obj, "name", file_obj)
return service.run(file_path, target_column, task_type, float(test_size), int(random_state))
with gr.Blocks(
title="Machine Learning Tabular Lab",
theme=gr.themes.Soft(primary_hue="green", secondary_hue="gray"),
) as demo:
gr.Markdown(
"""
# Machine Learning Tabular Lab
Upload a CSV dataset, choose the target column, and train a classic machine learning model on free CPU.
"""
)
dataset_input = gr.File(label="CSV Dataset", file_types=[".csv"])
target_input = gr.Textbox(label="Target Column", placeholder="target")
task_input = gr.Dropdown(
choices=["Auto", "Classification", "Regression"],
value="Auto",
label="Task Type",
)
with gr.Row():
test_size_input = gr.Slider(0.1, 0.4, value=0.2, step=0.05, label="Test Split")
random_state_input = gr.Slider(1, 999, value=42, step=1, label="Random State")
run_button = gr.Button("Train Model", variant="primary")
model_output = gr.Textbox(label="Selected Model", lines=1)
metric_output = gr.Textbox(label="Metrics", lines=6)
preview_output = gr.Textbox(label="Feature Preview", lines=8)
status_output = gr.Textbox(label="Status", lines=3)
run_button.click(
fn=train_model,
inputs=[dataset_input, target_input, task_input, test_size_input, random_state_input],
outputs=[model_output, metric_output, preview_output, status_output],
)
if __name__ == "__main__":
demo.launch()
|