tommytracx/thoxmini-virtual
0
1from fastapi import FastAPI, Request2from fastapi.responses import JSONResponse, StreamingResponse3import json4from typing import List, Dict, Any5 6app = FastAPI(title="ThoxMini Virtual - MeshStack Node")7 8DEVICE = "ThoxMini-Virtual"9NODE_ID = "virtual-thoxmini-01"10MESHSTACK_ACCOUNT = "dev@thox.ai"11 12ZEROGPU = {13 "text-to-image": "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev",14 "image-edit": "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium",15 "video": "https://huggingface.co/spaces/hotshotco/Hotshot-XL",16 "tts": "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"17}18 19SYSTEM_PROMPT = "You are ThoxMini, a compact multimodal edge device from THOX.ai. You run locally-first on CPU Spaces, proxy heavy models via ZeroGPU, and participate in the MeshStack mesh with ThoxAir and ThoxMini. Be precise, calm, and helpful."20 21@app.get("/")22def root():23 return {24 "device": DEVICE,25 "node_id": NODE_ID,26 "status": "online",27 "meshstack": MESHSTACK_ACCOUNT,28 "capabilities": ["general", "coding", "agentic", "text-to-image", "image-edit", "video-generation", "tts", "full-conversation"],29 "models": list(ZEROGPU.keys()) + ["qwen2.5-3b-local"]30 }31 32@app.get("/v1/models")33def models():34 return {"object": "list", "data": [{"id": m, "object": "model", "owned_by": "thox-virtual"} for m in ["qwen2.5-3b", "flux-dev", "sd3-medium", "mms-tts"]]}35 36@app.post("/v1/chat/completions")37async def chat(request: Request):38 data = await request.json()39 stream = data.get("stream", False)40 41 response_text = f"Hello from {DEVICE} (MeshStack node {NODE_ID}). I have full local models for general, coding, and agentic tasks. Heavy multimodal (image, video, TTS) is routed through ZeroGPU proxies and shared in the dev@thox.ai mesh."42 43 if stream:44 async def stream_gen():45 yield f'data: {json.dumps({"choices": [{"delta": {"content": response_text}}]})}\n\n'46 yield 'data: [DONE]\n\n'47 return StreamingResponse(stream_gen(), media_type="text/event-stream")48 49 return {"choices": [{"message": {"role": "assistant", "content": response_text}}]}50 51@app.post("/v1/audio/speech")52async def speech(request: Request):53 data = await request.json()54 text = data.get("input", "ThoxMini online.")55 return JSONResponse({56 "device": DEVICE,57 "audio_url": f"{ZEROGPU['tts']}?text={text}",58 "format": "mp3",59 "message": "TTS routed via ZeroGPU proxy - full conversation mode active"60 })61 62@app.get("/meshstack/register")63def register():64 return {65 "status": "registered",66 "account": MESHSTACK_ACCOUNT,67 "node": NODE_ID,68 "devices": ["ThoxMini-Virtual", "ThoxAir-Virtual", "ThoxMini-Virtual"],69 "shared_models": ["flux-dev", "sd3-medium", "video-gen", "tts"]70 }71 72print(f"๐ {DEVICE} virtual instance started - connected to {MESHSTACK_ACCOUNT} MeshStack")73 