Download backend/app/system/system_controller.py from modventures/character-studio: direct link, hf CLI and curl.
- Browser
- Download file 3.35 kB
-
https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/system/system_controller.py
- Command line
-
hf download hf://spaces/modventures/character-studio/backend/app/system/system_controller.py
-
curl -L -o system_controller.py https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/system/system_controller.py
3.35 kB
| import json | |
| from datetime import datetime, timezone | |
| import httpx | |
| from fastapi import APIRouter | |
| from app.config import settings | |
| from app.ai.provider_readiness import lightweight_ready | |
| router = APIRouter(prefix="/system", tags=["system"]) | |
| def status(): | |
| heartbeat = settings.assets_dir.parent / "worker-heartbeat.json" | |
| worker = False | |
| if heartbeat.exists(): | |
| try: | |
| timestamp = datetime.fromisoformat( | |
| json.loads(heartbeat.read_text())["updated_at"] | |
| ) | |
| worker = (datetime.now(timezone.utc) - timestamp).total_seconds() < 30 | |
| except (ValueError, KeyError, OSError): | |
| pass | |
| return { | |
| "worker": worker, | |
| "providers": { | |
| "dialogue": { | |
| "name": settings.dialogue_model, | |
| "configured": bool(settings.ollama_url), | |
| }, | |
| "speech": { | |
| "name": settings.speech_provider, | |
| "configured": bool(settings.speech_url), | |
| }, | |
| "video": { | |
| "name": settings.video_provider, | |
| "configured": bool(settings.video_url), | |
| }, | |
| }, | |
| "capabilities": { | |
| "scripted_dialogue": True, | |
| "performance_controls": False, | |
| "storyboard": True, | |
| "ai_dialogue": bool(settings.enable_ai_drafts and settings.ollama_url), | |
| "animated_video": bool( | |
| settings.enable_animated_renders | |
| and settings.speech_url | |
| and settings.video_url | |
| and (settings.video_provider != "sadtalker" or lightweight_ready()) | |
| ), | |
| }, | |
| "limitations": [ | |
| "Preset voices do not guarantee dialect or emotional delivery.", | |
| "SadTalker animates two portraits independently; shared reactions and body gestures are not generated.", | |
| "Review exact words, faces, lip-sync and listening reactions after GPU generation.", | |
| "Uploaded likenesses must depict fictional characters; third-party real-person likeness verification is not enabled.", | |
| ], | |
| } | |
| def check(): | |
| results = {} | |
| for name, url in [ | |
| ("dialogue", settings.ollama_url), | |
| ("speech", settings.speech_url), | |
| ("video", settings.video_url), | |
| ]: | |
| if not url: | |
| results[name] = {"ready": False, "message": "Not configured"} | |
| continue | |
| try: | |
| suffix = "/api/tags" if name == "dialogue" else "/health" | |
| response = httpx.get( | |
| url.rstrip("/") + suffix, | |
| headers={"Authorization": f"Bearer {settings.provider_token}"}, | |
| timeout=5, | |
| ) | |
| response.raise_for_status() | |
| ready = True | |
| if name == "dialogue": | |
| ready = settings.dialogue_model in { | |
| m["name"] for m in response.json().get("models", []) | |
| } | |
| results[name] = { | |
| "ready": ready, | |
| "message": "Connected" | |
| if ready | |
| else "Configured model is not installed", | |
| } | |
| except (httpx.HTTPError, ValueError, KeyError): | |
| results[name] = {"ready": False, "message": "Service not reachable"} | |
| return results | |