3morixd commited on
Commit
02f7506
·
verified ·
1 Parent(s): 46cd2d2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +41 -59
app.py CHANGED
@@ -1,59 +1,41 @@
1
- import gradio as gr
2
- import requests
3
- import json
4
-
5
- API_URL = "http://94.205.175.139:8081"
6
- API_KEY="d"a-demo-key-0001"
7
-
8
- def get_status():
9
- try:
10
- r = requests.get(f"{API_URL}/", timeout=5)
11
- data = r.json()
12
- return f"Status: {data.get('status', 'unknown')}
13
- Phones: {data.get('phones_connected', 0)}
14
- Models: {len(data.get('models', []))}
15
- Pricing: {data.get('pricing', {})}"
16
- except Exception as e:
17
- return f"API Error: {e}"
18
-
19
- def chat(message, model):
20
- try:
21
- r = requests.post(
22
- f"{API_URL}/v1/chat/completions",
23
- headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
24
- json={"model": model, "messages": [{"role": "user", "content": message}], "max_tokens": 50},
25
- timeout=60
26
- )
27
- data = r.json()
28
- content = data.get("choices", [{}])[0].get("message", {}).get("content", "No response")
29
- phone = data.get("phone_info", {})
30
- tps = phone.get("generation_tps", 0)
31
- serial = phone.get("serial", "unknown")
32
- return f"{content}
33
-
34
- ---
35
- Phone: {serial} | Speed: {tps} t/s"
36
- except Exception as e:
37
- return f"Error: {e}"
38
-
39
- with gr.Blocks(title="dispatchAI Phone Farm Monitor") as app:
40
- gr.Markdown("# dispatchAI Phone Farm Monitor")
41
- with gr.Row():
42
- status_btn = gr.Button("Refresh Status")
43
- status_out = gr.Textbox(label="Status", lines=5)
44
- status_btn.click(get_status, outputs=status_out)
45
-
46
- gr.Markdown("## Test Chat")
47
- with gr.Row():
48
- model = gr.Dropdown([
49
- "dispatchAI/SmolLM2-135M-Instruct-mobile",
50
- "dispatchAI/Qwen2.5-0.5B-Instruct-mobile-int4",
51
- "dispatchAI/Llama-3.2-1B-Instruct-Q4-mobile"
52
- ], label="Model", value="dispatchAI/SmolLM2-135M-Instruct-mobile")
53
- with gr.Row():
54
- msg = gr.Textbox(label="Message", value="What is the capital of France?")
55
- send = gr.Button("Send")
56
- out = gr.Textbox(label="Response", lines=5)
57
- send.click(chat, inputs=[msg, model], outputs=out)
58
-
59
- app.launch()
 
1
+ import gradio as gr
2
+ import httpx
3
+ import asyncio
4
+ import json
5
+
6
+ BASE = "http://127.0.0.1:8081"
7
+
8
+ def get_status():
9
+ try:
10
+ r = httpx.get(f"{BASE}/", timeout=5.0)
11
+ data = r.json()
12
+ return f"API: {data["status"]}
13
+ Phones: {data["phones_connected"]}
14
+ Models: {len(data["models"])}"
15
+ except:
16
+ return "API offline"
17
+
18
+ def chat(message):
19
+ try:
20
+ r = httpx.post(f"{BASE}/v1/chat/completions",
21
+ headers={"Authorization": "Bearer da-demo-key-0001", "Content-Type": "application/json"},
22
+ json={"model": "dispatchAI/SmolLM2-135M-Instruct-mobile", "messages": [{"role": "user", "content": message}], "max_tokens": 50},
23
+ timeout=120.0)
24
+ data = r.json()
25
+ return data["choices"][0]["message"]["content"]
26
+ except Exception as e:
27
+ return f"Error: {e}"
28
+
29
+ with gr.Blocks(title="dispatchAI Monitor") as app:
30
+ gr.Markdown("# dispatchAI Phone Farm Monitor")
31
+ with gr.Row():
32
+ status_btn = gr.Button("Check Status")
33
+ status_out = gr.Textbox(label="Status")
34
+ status_btn.click(get_status, outputs=status_out)
35
+ with gr.Row():
36
+ msg = gr.Textbox(label="Message", placeholder="Ask a question...")
37
+ send_btn = gr.Button("Send")
38
+ response = gr.Textbox(label="Response")
39
+ send_btn.click(chat, inputs=msg, outputs=response)
40
+
41
+ app.launch()