3morixd's picture
Upload app.py with huggingface_hub
02f7506 verified
Raw
History Blame Contribute Delete
1.39 kB
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()