CoolFace
Apppublic

KB-Infinity-Tech/AIMSRICHackatonDay1

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes
demo.py124 linesDownload Raw Back to src
1"""2demo.py — Quick demo for hackathon judges / live defense3Runs everything in < 5 seconds. All output is self-explanatory.4"""5 6from pricer import (7    Product, suggest_price, simulate_7_days,8    format_sms, print_comparison_report, freshness_factor9)10 11 12def demo_single_price():13    """Show how one pricing call works, step by step."""14    print("\n" + "━"*60)15    print("  DEMO 1: Single Price Recommendation")16    print("━"*60)17 18    tomato = Product(19        sku="TOMATO-A",20        cost=1000,21        shelf_life_days=7,22        p_ref=1800,23        Q0=50,24        alpha=1.5,25    )26 27    competitors = [1600, 1700, 1900]28 29    for age in [0, 2, 3.5, 5, 6]:30        result = suggest_price(tomato, age, competitors)31        freshness = result["freshness"]32        price = result["suggested_price"]33        label = result["freshness_label"]34        print(f"  Day {age:>3.1f} | Freshness: {freshness:.3f} ({label:<10}) "35              f"→ Price: {price:>7.0f} UGX | "36              f"Margin: {result['margin_pct']:>5.1f}%")37 38 39def demo_freshness_table():40    """Show the sigmoid freshness curve — great for interview visuals."""41    print("\n" + "━"*60)42    print("  DEMO 2: Freshness Curve (why sigmoid beats linear)")43    print("━"*60)44    print(f"  {'Day':<6} {'Sigmoid':>10} {'Linear':>10} {'Difference':>12}")45    print("  " + "-"*42)46 47    shelf = 748    for day in range(8):49        sigmoid = freshness_factor(day, shelf)50        linear = max(0, 1 - day / shelf)51        diff = sigmoid - linear52        bar = "█" * int(sigmoid * 20)53        print(f"  {day:<6} {sigmoid:>10.3f} {linear:>10.3f} {diff:>+12.3f}  {bar}")54 55 56def demo_what_at_half_life():57    """Interview: what happens at half shelf life?"""58    print("\n" + "━"*60)59    print("  DEMO 3: The Half-Life Moment (key interview talking point)")60    print("━"*60)61 62    tomato = Product(63        sku="TOMATO-A", cost=1000, shelf_life_days=7,64        p_ref=1800, Q0=50, alpha=1.5,65    )66    half_life = tomato.shelf_life_days / 2  # Day 3.567 68    fresh_result = suggest_price(tomato, 0, [1600, 1700])69    mid_result   = suggest_price(tomato, half_life, [1600, 1700])70    late_result  = suggest_price(tomato, 6, [1600, 1700])71 72    print(f"  Day 0   (fresh):     {fresh_result['suggested_price']:>7.0f} UGX — {fresh_result['freshness_label']}")73    print(f"  Day 3.5 (half-life): {mid_result['suggested_price']:>7.0f} UGX — {mid_result['freshness_label']}")74    print(f"  Day 6   (near-exp):  {late_result['suggested_price']:>7.0f} UGX — {late_result['freshness_label']}")75    print()76    price_drop = (fresh_result['suggested_price'] - mid_result['suggested_price'])77    print(f"  → At half-life, price drops {price_drop:.0f} UGX ({price_drop/fresh_result['suggested_price']*100:.0f}%)")78    print("  → This is the inflection point — aggressive discounting begins")79    print("  → Exactly where the sigmoid inflects: steepest rate of change")80 81 82def demo_sms():83    """Show SMS output for different freshness levels."""84    print("\n" + "━"*60)85    print("  DEMO 4: SMS Output (African Market Feature)")86    print("━"*60)87 88    tomato = Product(89        sku="TOM", cost=1000, shelf_life_days=7,90        p_ref=1800, Q0=50, alpha=1.5,91    )92 93    for age in [0, 3, 5, 6]:94        result = suggest_price(tomato, age, [1600, 1700, 1900])95        sms = format_sms(result, "UGX")96        print(f"  Day {age}: [{len(sms):>3}chr] {sms}")97 98 99def demo_simulation():100    """Full 7-day comparison across 3 strategies."""101    tomato = Product(102        sku="TOMATO", cost=1000, shelf_life_days=7,103        p_ref=1800, Q0=50, alpha=1.5,104    )105    print_comparison_report(tomato, [1600, 1700, 1900])106 107    # Second product: bread (shorter shelf life, different dynamics)108    bread = Product(109        sku="BREAD", cost=2500, shelf_life_days=3,110        p_ref=4000, Q0=30, alpha=2.0,111        k=10.0  # Sharper cliff for bread112    )113    print_comparison_report(bread, [3800, 3900])114 115 116if __name__ == "__main__":117    demo_single_price()118    demo_freshness_table()119    demo_what_at_half_life()120    demo_sms()121    demo_simulation()122 123    print("\n✅ All demos complete. Ready for live defense.")124