size_predictor / app.py
Prince Vaviya
improved reasoning
ba180cd
import gradio as gr
from size_rules import evaluate_size, apply_fit_preference
def predict_size(chest, waist, bicep, shoulder, fit_pref):
data = {
"chest": chest,
"waist": waist,
"bicep": bicep,
"shoulder": shoulder
}
base_size, base_reason = evaluate_size(data)
final_size, fit_reason = apply_fit_preference(base_size, fit_pref, data)
explanation = {
"recommended_size": final_size,
"fit_preference": fit_pref,
"confidence": "high",
"reason": f"{base_reason} {fit_reason}"
}
html_output = f"""
<div style="
background-color: #d1fae5;
color: #065f46;
font-size: 32px;
font-weight: bold;
text-align: center;
border: 2px solid #10b981;
padding: 20px;
border-radius: 8px;
">
{final_size}
</div>
"""
return html_output, explanation
with gr.Blocks(title="AI Size Recommendation Engine") as demo:
gr.Markdown("# AI Size Recommendation Engine")
gr.Markdown("Enter your body measurements (in inches) to get a deterministic size recommendation.")
with gr.Row():
with gr.Column():
chest = gr.Number(label="Chest (inches)", value=38.0, step=0.5)
waist = gr.Number(label="Waist (inches)", value=32.0, step=0.5)
bicep = gr.Number(label="Bicep (inches)", value=13.0, step=0.5)
shoulder = gr.Number(label="Shoulder (inches)", value=46.0, step=0.5)
fit = gr.Dropdown(choices=["Slim", "Regular", "Loose"], label="Fit Preference", value="Regular")
submit_btn = gr.Button("Predict Size", variant="primary")
with gr.Column():
gr.Markdown("### Recommended Size")
output_size = gr.HTML()
output_json = gr.JSON(label="Explainable AI Output")
# Prediction event
submit_btn.click(
fn=predict_size,
inputs=[chest, waist, bicep, shoulder, fit],
outputs=[output_size, output_json]
)
if __name__ == "__main__":
demo.launch()