File size: 3,189 Bytes
ce139b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
import gradio as gr

def calculate_cost(daily_queries, cloud_cost_per_1k, days=365):
    """Compare cloud vs on-device costs."""
    # Cloud cost
    cloud_daily = (daily_queries / 1000) * cloud_cost_per_1k
    cloud_annual = cloud_daily * days
    
    # On-device cost (one-time model download, then $0)
    # Average model size: 500MB, data cost: $1/GB (conservative)
    onetime_download_cost = 0.5  # 500MB at $1/GB
    on_device_annual = onetime_download_cost  # No per-query cost
    
    # Savings
    savings = cloud_annual - on_device_annual
    savings_pct = (savings / cloud_annual * 100) if cloud_annual > 0 else 0
    
    result = f"""
## πŸ’° Cost Comparison: Cloud vs On-Device

| Metric | Cloud API | dispatchAI On-Device |
|--------|-----------|---------------------|
| Cost per 1K queries | ${cloud_cost_per_1k:.2f} | $0.00 |
| Daily cost | ${cloud_daily:.2f} | $0.00 |
| Monthly cost | ${cloud_daily * 30:.2f} | $0.00 |
| **Annual cost** | **${cloud_annual:.2f}** | **${on_device_annual:.2f}** |
| One-time setup | $0 | ${onetime_download_cost:.2f} (data) |

## πŸ“Š Your Savings

- **Annual savings: ${savings:.2f}**
- **Savings: {savings_pct:.0f}%**
- **5-year savings: ${savings * 5:.2f}**
- **10-year savings: ${savings * 10:.2f}**

## Why On-Device Wins

1. **Zero per-query cost** β€” Once the model is on the phone, every inference is free
2. **No network needed** β€” Works offline, on airplanes, in tunnels
3. **Zero latency** β€” No round-trip to a server
4. **Privacy** β€” Data never leaves the device
5. **No rate limits** β€” Process a million queries, still $0

## dispatchAI Models for On-Device

| Model | Size | Best For |
|-------|------|----------|
| SmolLM2-135M | 270MB | Classification, simple QA |
| Qwen2.5-0.5B | 350MB (Q4) | Chat, summarization |
| Llama-3.2-1B | 650MB (Q4) | General assistant |
| Llama-3.2-3B | 2.1GB (Q5) | Complex tasks |

[Browse all 39 models β†’](https://huggingface.co/dispatchAI)
"""
    return result

with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Phone vs Cloud Cost Calculator") as demo:
    gr.Markdown("""
    # πŸ’° Phone vs Cloud Cost Calculator
    
    See how much you save by running AI on-device with dispatchAI instead of paying for cloud API inference.
    """)
    
    with gr.Row():
        daily_queries = gr.Slider(100, 100000, value=10000, step=100, 
                                   label="Daily Queries", info="How many AI queries per day?")
        cloud_cost = gr.Slider(0.1, 10.0, value=0.5, step=0.1,
                                label="Cloud API Cost ($/1K queries)",
                                info="What does your cloud API charge per 1000 queries?")
    
    calc_btn = gr.Button("Calculate Savings", variant="primary", size="lg")
    output = gr.Markdown()
    
    calc_btn.click(fn=calculate_cost, inputs=[daily_queries, cloud_cost], outputs=output)
    
    # Pre-populate with defaults
    demo.load(fn=calculate_cost, inputs=[daily_queries, cloud_cost], outputs=output)
    
    gr.Markdown("""
    ---
    πŸš€ [dispatchAI](https://huggingface.co/dispatchAI) β€” Small. Mobile. Free. UAE-built.
    """)

if __name__ == "__main__":
    demo.launch()