Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
MODELS = [
|
| 5 |
+
{"name": "SmolLM2-135M-Instruct-mobile", "size_mb": 101, "ram_mb": 400, "tps": 59.7, "phone_tps": 46.0},
|
| 6 |
+
{"name": "Qwen2.5-0.5B-Instruct-mobile-int4", "size_mb": 469, "ram_mb": 550, "tps": 12.5, "phone_tps": 23.2},
|
| 7 |
+
{"name": "Llama-3.2-1B-Instruct-Q4-mobile", "size_mb": 770, "ram_mb": 1100, "tps": 11.3, "phone_tps": 5.4},
|
| 8 |
+
{"name": "TinyLlama-1.1B-Chat-Q5-mobile", "size_mb": 800, "ram_mb": 1200, "tps": 10.9, "phone_tps": ""},
|
| 9 |
+
{"name": "Gemma-2-2B-IT-Q5-mobile", "size_mb": 1500, "ram_mb": 2200, "tps": 5.7, "phone_tps": ""},
|
| 10 |
+
{"name": "Llama-3.2-3B-Instruct-Q5-mobile", "size_mb": 2100, "ram_mb": 2700, "tps": 2.6, "phone_tps": ""},
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
def check_ram(ram_mb: int) -> str:
|
| 14 |
+
"""Check which dispatchAI models fit in a given RAM budget.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
ram_mb: Available RAM in MB
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
JSON with models that fit and their specs
|
| 21 |
+
"""
|
| 22 |
+
fitting = [m for m in MODELS if m["ram_mb"] <= ram_mb]
|
| 23 |
+
not_fitting = [m for m in MODELS if m["ram_mb"] > ram_mb]
|
| 24 |
+
|
| 25 |
+
return json.dumps({
|
| 26 |
+
"ram_budget_mb": ram_mb,
|
| 27 |
+
"models_that_fit": len(fitting),
|
| 28 |
+
"best_option": fitting[0] if fitting else None,
|
| 29 |
+
"all_fitting": fitting,
|
| 30 |
+
"too_large": [{"name": m["name"], "needs_mb": m["ram_mb"]} for m in not_fitting],
|
| 31 |
+
}, indent=2)
|
| 32 |
+
|
| 33 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), title="RAM Calculator") as demo:
|
| 34 |
+
gr.Markdown("# 💾 Phone RAM Calculator (MCP)")
|
| 35 |
+
ram = gr.Slider(512, 8192, value=2048, step=256, label="Available RAM (MB)")
|
| 36 |
+
btn = gr.Button("Check", variant="primary")
|
| 37 |
+
out = gr.Textbox(label="Results (JSON)", lines=15)
|
| 38 |
+
btn.click(fn=check_ram, inputs=ram, outputs=out)
|
| 39 |
+
gr.Markdown("---\n🚀 [dispatchAI](https://huggingface.co/dispatchAI)")
|
| 40 |
+
demo.launch(mcp_server=True)
|