# AI Assistance Declaration: # Parts of this script were assisted by ChatGPT GPT. # AI assistance was limited to code suggestions, debugging tips, or documentation wording. # All algorithmic design, implementation decisions, and final code structure were created and verified by the project team. import gradio as gr import requests # Cloud Run API URL API_BASE = "https://ecommerce-ml-346297770564.us-east1.run.app" # Numeric features numeric_features = { "shipping_fee": 6, "tax": 6, "avg_order_value": 6, "day_of_week": 6 } # Binary features (0/1) but UI uses "Yes"/"No" binary_features = { "status_cancelled": 1, "status_completed": 1, "status_processing": 1, "status_returned": 0, "status_shipped": 1, "is_holiday": 1 } # Create widgets numeric_inputs = [ gr.Number(label=f"📊 {f.replace('_',' ').title()}", value=v) for f, v in numeric_features.items() ] binary_inputs = [ gr.Radio( label=f"🔘 {f.replace('_',' ').title()}", choices=["Yes (1)", "No (0)"], value="Yes (1)" if v == 1 else "No (0)" ) for f, v in binary_features.items() ] feature_names = list(numeric_features.keys()) + list(binary_features.keys()) all_inputs = numeric_inputs + binary_inputs def parse_value(v): if isinstance(v, str): return 1 if "Yes" in v else 0 return v def predict_fn(*values): parsed_vals = [parse_value(v) for v in values] features = {f: v for f, v in zip(feature_names, parsed_vals)} payload = {"features": features} response = requests.post(f"{API_BASE}/predict", json=payload) if response.status_code != 200: return f"❌ API Error: {response.text}" preds = response.json()["predictions"] # prediction UI html = """
{k}: {v:.4f}
""" html += "