3morixd commited on
Commit
ce139b3
Β·
verified Β·
1 Parent(s): 4b630e5

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def calculate_cost(daily_queries, cloud_cost_per_1k, days=365):
4
+ """Compare cloud vs on-device costs."""
5
+ # Cloud cost
6
+ cloud_daily = (daily_queries / 1000) * cloud_cost_per_1k
7
+ cloud_annual = cloud_daily * days
8
+
9
+ # On-device cost (one-time model download, then $0)
10
+ # Average model size: 500MB, data cost: $1/GB (conservative)
11
+ onetime_download_cost = 0.5 # 500MB at $1/GB
12
+ on_device_annual = onetime_download_cost # No per-query cost
13
+
14
+ # Savings
15
+ savings = cloud_annual - on_device_annual
16
+ savings_pct = (savings / cloud_annual * 100) if cloud_annual > 0 else 0
17
+
18
+ result = f"""
19
+ ## πŸ’° Cost Comparison: Cloud vs On-Device
20
+
21
+ | Metric | Cloud API | dispatchAI On-Device |
22
+ |--------|-----------|---------------------|
23
+ | Cost per 1K queries | ${cloud_cost_per_1k:.2f} | $0.00 |
24
+ | Daily cost | ${cloud_daily:.2f} | $0.00 |
25
+ | Monthly cost | ${cloud_daily * 30:.2f} | $0.00 |
26
+ | **Annual cost** | **${cloud_annual:.2f}** | **${on_device_annual:.2f}** |
27
+ | One-time setup | $0 | ${onetime_download_cost:.2f} (data) |
28
+
29
+ ## πŸ“Š Your Savings
30
+
31
+ - **Annual savings: ${savings:.2f}**
32
+ - **Savings: {savings_pct:.0f}%**
33
+ - **5-year savings: ${savings * 5:.2f}**
34
+ - **10-year savings: ${savings * 10:.2f}**
35
+
36
+ ## Why On-Device Wins
37
+
38
+ 1. **Zero per-query cost** β€” Once the model is on the phone, every inference is free
39
+ 2. **No network needed** β€” Works offline, on airplanes, in tunnels
40
+ 3. **Zero latency** β€” No round-trip to a server
41
+ 4. **Privacy** β€” Data never leaves the device
42
+ 5. **No rate limits** β€” Process a million queries, still $0
43
+
44
+ ## dispatchAI Models for On-Device
45
+
46
+ | Model | Size | Best For |
47
+ |-------|------|----------|
48
+ | SmolLM2-135M | 270MB | Classification, simple QA |
49
+ | Qwen2.5-0.5B | 350MB (Q4) | Chat, summarization |
50
+ | Llama-3.2-1B | 650MB (Q4) | General assistant |
51
+ | Llama-3.2-3B | 2.1GB (Q5) | Complex tasks |
52
+
53
+ [Browse all 39 models β†’](https://huggingface.co/dispatchAI)
54
+ """
55
+ return result
56
+
57
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="Phone vs Cloud Cost Calculator") as demo:
58
+ gr.Markdown("""
59
+ # πŸ’° Phone vs Cloud Cost Calculator
60
+
61
+ See how much you save by running AI on-device with dispatchAI instead of paying for cloud API inference.
62
+ """)
63
+
64
+ with gr.Row():
65
+ daily_queries = gr.Slider(100, 100000, value=10000, step=100,
66
+ label="Daily Queries", info="How many AI queries per day?")
67
+ cloud_cost = gr.Slider(0.1, 10.0, value=0.5, step=0.1,
68
+ label="Cloud API Cost ($/1K queries)",
69
+ info="What does your cloud API charge per 1000 queries?")
70
+
71
+ calc_btn = gr.Button("Calculate Savings", variant="primary", size="lg")
72
+ output = gr.Markdown()
73
+
74
+ calc_btn.click(fn=calculate_cost, inputs=[daily_queries, cloud_cost], outputs=output)
75
+
76
+ # Pre-populate with defaults
77
+ demo.load(fn=calculate_cost, inputs=[daily_queries, cloud_cost], outputs=output)
78
+
79
+ gr.Markdown("""
80
+ ---
81
+ πŸš€ [dispatchAI](https://huggingface.co/dispatchAI) β€” Small. Mobile. Free. UAE-built.
82
+ """)
83
+
84
+ if __name__ == "__main__":
85
+ demo.launch()