Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,59 +1,41 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def get_status():
|
| 9 |
-
try:
|
| 10 |
-
r =
|
| 11 |
-
data = r.json()
|
| 12 |
-
return f"
|
| 13 |
-
Phones: {data
|
| 14 |
-
Models: {len(data
|
| 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 |
-
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|