Spaces:
Running
Running
File size: 2,133 Bytes
7a83d16 6445bd1 7a83d16 17b6c6d 7a83d16 17b6c6d 7a83d16 ba180cd 7a83d16 17b6c6d 7a83d16 17b6c6d 7a83d16 | 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 | 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()
|