Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- README.md +24 -12
- app (1).py +55 -0
- requirements (1).txt +5 -0
README.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LEGO Brick Classification (Classical AutoML)
|
| 2 |
+
|
| 3 |
+
**Model repo:** [Iris314/classical-automl-model](https://huggingface.co/Iris314/classical-automl-model)
|
| 4 |
+
**Dataset:** [aedupuga/lego-sizes](https://huggingface.co/datasets/aedupuga/lego-sizes)
|
| 5 |
+
|
| 6 |
+
## About
|
| 7 |
+
This model classifies LEGO pieces into three types: **Standard, Flat, Sloped**
|
| 8 |
+
Inputs: `Length`, `Height`, `Width`, `Studs`.
|
| 9 |
+
|
| 10 |
+
- **Model:** AutoML (best model = LightGBM, via AutoGluon)
|
| 11 |
+
- **Task:** Tabular classification
|
| 12 |
+
- **Limitations:** Synthetic dataset (augmented from 30 → 300 samples); educational use only.
|
| 13 |
+
|
| 14 |
+
## Demo
|
| 15 |
+
Gradio interface allows:
|
| 16 |
+
- Single-record input via sliders
|
| 17 |
+
- Example inputs (3 presets)
|
| 18 |
+
- Prediction (most likely brick type)
|
| 19 |
+
- Class probabilities
|
| 20 |
+
|
| 21 |
+
## Acknowledgments
|
| 22 |
+
- Model by Xinxuan Tang (CMU), dataset curated by Anuhya Edupuganti (CMU).
|
| 23 |
+
- This Gradio app was implemented for CMU course HW3.
|
| 24 |
+
- GenAI disclosure: ChatGPT assisted in generating scaffolding code and documentation. All outputs were reviewed and edited.
|
app (1).py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from autogluon.tabular import TabularPredictor
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
import os, zipfile
|
| 6 |
+
|
| 7 |
+
REPO_ID = "Iris314/classical-automl-model"
|
| 8 |
+
ZIP_FILE = "lego_predictor_dir.zip"
|
| 9 |
+
|
| 10 |
+
local_zip = hf_hub_download(repo_id=REPO_ID, filename=ZIP_FILE)
|
| 11 |
+
|
| 12 |
+
extract_dir = "lego_predictor_dir"
|
| 13 |
+
os.makedirs(extract_dir, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
with zipfile.ZipFile(local_zip, 'r') as zip_ref:
|
| 16 |
+
zip_ref.extractall(extract_dir)
|
| 17 |
+
|
| 18 |
+
predictor = TabularPredictor.load(extract_dir)
|
| 19 |
+
|
| 20 |
+
def predict_brick(length, height, width, studs):
|
| 21 |
+
record = pd.DataFrame([{
|
| 22 |
+
"Length": length,
|
| 23 |
+
"Height": height,
|
| 24 |
+
"Width": width,
|
| 25 |
+
"Studs": studs
|
| 26 |
+
}])
|
| 27 |
+
pred = predictor.predict(record)[0]
|
| 28 |
+
proba = predictor.predict_proba(record).iloc[0].to_dict()
|
| 29 |
+
return f"Prediction: {pred}", proba
|
| 30 |
+
|
| 31 |
+
with gr.Blocks(title="LEGO Brick Classifier") as demo:
|
| 32 |
+
gr.Markdown("## LEGO Brick Classification\nPredict Standard / Flat / Sloped")
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
length = gr.Slider(1, 10, step=0.5, value=4, label="Length")
|
| 36 |
+
height = gr.Slider(0.5, 5, step=0.1, value=1.2, label="Height")
|
| 37 |
+
width = gr.Slider(1, 10, step=0.5, value=2, label="Width")
|
| 38 |
+
studs = gr.Slider(0, 12, step=1, value=4, label="Studs")
|
| 39 |
+
btn = gr.Button("Predict")
|
| 40 |
+
with gr.Column():
|
| 41 |
+
out_label = gr.Textbox(label="Prediction")
|
| 42 |
+
out_probs = gr.Label(label="Class Probabilities")
|
| 43 |
+
|
| 44 |
+
btn.click(predict_brick, [length, height, width, studs], [out_label, out_probs])
|
| 45 |
+
|
| 46 |
+
gr.Examples(
|
| 47 |
+
examples=[
|
| 48 |
+
[4, 1.2, 2, 4],
|
| 49 |
+
[6, 0.5, 2, 6],
|
| 50 |
+
[3, 2.0, 2, 2]
|
| 51 |
+
],
|
| 52 |
+
inputs=[length, height, width, studs]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
demo.launch()
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
+
autogluon==1.1.1
|
| 3 |
+
pandas
|
| 4 |
+
numpy
|
| 5 |
+
huggingface_hub
|