File size: 1,385 Bytes
02f7506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import httpx
import asyncio
import json

BASE = "http://127.0.0.1:8081"

def get_status():
    try:
        r = httpx.get(f"{BASE}/", timeout=5.0)
        data = r.json()
        return f"API: {data["status"]}

Phones: {data["phones_connected"]}

Models: {len(data["models"])}"
    except:
        return "API offline"

def chat(message):
    try:
        r = httpx.post(f"{BASE}/v1/chat/completions",
            headers={"Authorization": "Bearer da-demo-key-0001", "Content-Type": "application/json"},
            json={"model": "dispatchAI/SmolLM2-135M-Instruct-mobile", "messages": [{"role": "user", "content": message}], "max_tokens": 50},
            timeout=120.0)
        data = r.json()
        return data["choices"][0]["message"]["content"]
    except Exception as e:
        return f"Error: {e}"

with gr.Blocks(title="dispatchAI Monitor") as app:
    gr.Markdown("# dispatchAI Phone Farm Monitor")
    with gr.Row():
        status_btn = gr.Button("Check Status")
        status_out = gr.Textbox(label="Status")
    status_btn.click(get_status, outputs=status_out)
    with gr.Row():
        msg = gr.Textbox(label="Message", placeholder="Ask a question...")
        send_btn = gr.Button("Send")
        response = gr.Textbox(label="Response")
    send_btn.click(chat, inputs=msg, outputs=response)

app.launch()