glasscube 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- glasscube/__init__.py +7 -0
- glasscube/__main__.py +3 -0
- glasscube/app/__init__.py +4 -0
- glasscube/app/frontend_dev.py +68 -0
- glasscube/app/main.py +120 -0
- glasscube/app/pages.py +185 -0
- glasscube/app/settings.py +93 -0
- glasscube/assistant/__init__.py +3 -0
- glasscube/assistant/assistant.py +370 -0
- glasscube/assistant/llm/__init__.py +5 -0
- glasscube/assistant/llm/backends/__init__.py +4 -0
- glasscube/assistant/llm/backends/anthropic.py +45 -0
- glasscube/assistant/llm/backends/openai_compat.py +27 -0
- glasscube/assistant/llm/base.py +21 -0
- glasscube/assistant/llm/client.py +20 -0
- glasscube/assistant/rag/__init__.py +11 -0
- glasscube/assistant/rag/chunker.py +68 -0
- glasscube/assistant/rag/embedder.py +37 -0
- glasscube/assistant/rag/retriever.py +28 -0
- glasscube/assistant/rag/seed_corpus/about_ieee_insat.txt +5 -0
- glasscube/assistant/rag/seed_corpus/ieee_insat_events.md +5 -0
- glasscube/assistant/rag/seed_corpus/smart_mirror_project.txt +4 -0
- glasscube/assistant/rag/store.py +107 -0
- glasscube/assistant/stt/__init__.py +5 -0
- glasscube/assistant/stt/vad.py +148 -0
- glasscube/assistant/stt/wake_word.py +186 -0
- glasscube/assistant/stt/whisper.py +97 -0
- glasscube/assistant/tools/__init__.py +3 -0
- glasscube/assistant/tools/manager.py +25 -0
- glasscube/assistant/tts/__init__.py +3 -0
- glasscube/assistant/tts/piper.py +63 -0
- glasscube/config/__init__.py +13 -0
- glasscube/config/env.py +16 -0
- glasscube/config/json_config/default_gesture_config.json +8 -0
- glasscube/config/json_config/default_widget_event_bindings.json +58 -0
- glasscube/config/loader.py +21 -0
- glasscube/config/paths.py +32 -0
- glasscube/content/__init__.py +23 -0
- glasscube/content/cache.py +97 -0
- glasscube/content/config.py +68 -0
- glasscube/content/indexer.py +54 -0
- glasscube/content/routing.py +180 -0
- glasscube/content/sync.py +420 -0
- glasscube/content/templates.py +122 -0
- glasscube/core/__init__.py +3 -0
- glasscube/core/actions.py +48 -0
- glasscube/core/callables.py +23 -0
- glasscube/core/navigation.py +66 -0
- glasscube/core/state_manager.py +82 -0
- glasscube/core/widget_events.py +120 -0
- glasscube/hal/__init__.py +3 -0
- glasscube/hal/hal.py +131 -0
- glasscube/server/__init__.py +3 -0
- glasscube/server/app.py +241 -0
- glasscube/server/camera.py +147 -0
- glasscube/server/camera_preview.py +54 -0
- glasscube/server/hand_pointer.py +42 -0
- glasscube/server/static_ui.py +47 -0
- glasscube/server/websocket.py +54 -0
- glasscube/server/widget_data.py +33 -0
- glasscube/ui/assets/5 1-CpBR8EWH.png +0 -0
- glasscube/ui/assets/index-BB9bg-We.js +9 -0
- glasscube/ui/assets/index-CQRKDs3v.css +1 -0
- glasscube/ui/assets/press-start-2p-cyrillic-400-normal-DBn7fddJ.woff2 +0 -0
- glasscube/ui/assets/press-start-2p-cyrillic-ext-400-normal-CIYZrvmP.woff2 +0 -0
- glasscube/ui/assets/press-start-2p-greek-400-normal-DQfalijU.woff2 +0 -0
- glasscube/ui/assets/press-start-2p-latin-400-normal-KLytu4cr.woff +0 -0
- glasscube/ui/assets/press-start-2p-latin-400-normal-_wFEWmAB.woff2 +0 -0
- glasscube/ui/assets/press-start-2p-latin-ext-400-normal-DBgyq7ky.woff +0 -0
- glasscube/ui/assets/press-start-2p-latin-ext-400-normal-DpfYvR5A.woff2 +0 -0
- glasscube/ui/assets/sleeping-abdo-J4WKKI3q.gif +0 -0
- glasscube/ui/assets/transition-abdo-DsBJJ6fU.gif +0 -0
- glasscube/ui/assets/vt323-latin-400-normal-Dqn9ZSPj.woff +0 -0
- glasscube/ui/assets/vt323-latin-400-normal-wDgJuOC9.woff2 +0 -0
- glasscube/ui/assets/vt323-latin-ext-400-normal-DqOq58ri.woff +0 -0
- glasscube/ui/assets/vt323-latin-ext-400-normal-iUdYUaX4.woff2 +0 -0
- glasscube/ui/assets/vt323-vietnamese-400-normal-D0VnvwZ9.woff2 +0 -0
- glasscube/ui/assets/vt323-vietnamese-400-normal-D_5Q7Vcv.woff +0 -0
- glasscube/ui/index.html +13 -0
- glasscube/vision/__init__.py +43 -0
- glasscube/vision/debug_overlay.py +141 -0
- glasscube/vision/gesture_detector.py +178 -0
- glasscube/vision/gesture_types.py +54 -0
- glasscube/vision/gestures/__init__.py +22 -0
- glasscube/vision/gestures/base.py +198 -0
- glasscube/vision/gestures/click.py +38 -0
- glasscube/vision/gestures/default_set.py +21 -0
- glasscube/vision/gestures/pinch.py +44 -0
- glasscube/vision/gestures/scroll.py +37 -0
- glasscube/vision/gestures/swipe.py +23 -0
- glasscube/vision/gestures/two_fingers_swipe.py +39 -0
- glasscube/vision/gestures/zoom.py +52 -0
- glasscube/vision/hand_data.py +43 -0
- glasscube/vision/landmark_detector.py +104 -0
- glasscube/widgets/__init__.py +21 -0
- glasscube/widgets/base.py +75 -0
- glasscube/widgets/calendar.py +13 -0
- glasscube/widgets/drawing.py +57 -0
- glasscube/widgets/events.py +16 -0
- glasscube/widgets/games.py +15 -0
- glasscube/widgets/news.py +7 -0
- glasscube/widgets/providers/__init__.py +12 -0
- glasscube/widgets/providers/mongo_calendar.py +44 -0
- glasscube/widgets/providers/open_meteo.py +40 -0
- glasscube/widgets/providers/qr_catalog.py +6 -0
- glasscube/widgets/qr_gallery.py +7 -0
- glasscube/widgets/text.py +85 -0
- glasscube/widgets/weather.py +11 -0
- glasscube-0.1.0.dist-info/METADATA +203 -0
- glasscube-0.1.0.dist-info/RECORD +114 -0
- glasscube-0.1.0.dist-info/WHEEL +5 -0
- glasscube-0.1.0.dist-info/entry_points.txt +2 -0
- glasscube-0.1.0.dist-info/licenses/LICENSE +21 -0
- glasscube-0.1.0.dist-info/top_level.txt +1 -0
glasscube/__init__.py
ADDED
glasscube/__main__.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
# <repo>/frontend, next to backend/. Only exists in a checkout of the repo, not in a pip install.
|
|
8
|
+
DEFAULT_FRONTEND_DIR = Path(__file__).resolve().parents[3] / "frontend"
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FrontendLauncher:
|
|
14
|
+
"""Dev convenience: runs the frontend's Vite dev server (npm install first if needed).
|
|
15
|
+
|
|
16
|
+
The frontend is a separate app; this only saves starting it by hand. It is
|
|
17
|
+
told the backend's WebSocket port through VITE_GLASSCUBE_WS_PORT.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, frontend_dir=None, host="localhost", port=5173, ws_port=8080):
|
|
21
|
+
self.frontend_dir = Path(frontend_dir) if frontend_dir else DEFAULT_FRONTEND_DIR
|
|
22
|
+
self.host = host
|
|
23
|
+
self.port = port
|
|
24
|
+
self.ws_port = ws_port
|
|
25
|
+
self.process = None
|
|
26
|
+
|
|
27
|
+
def available(self):
|
|
28
|
+
"""True when there's a frontend/ checkout (with its package.json) and npm to run it."""
|
|
29
|
+
return (self.frontend_dir / "package.json").is_file() and shutil.which("npm") is not None
|
|
30
|
+
|
|
31
|
+
async def start(self):
|
|
32
|
+
npm = shutil.which("npm")
|
|
33
|
+
if not self.frontend_dir.exists():
|
|
34
|
+
logger.warning("Skipping frontend launch: directory not found at %s", self.frontend_dir)
|
|
35
|
+
return
|
|
36
|
+
if npm is None:
|
|
37
|
+
logger.warning("Skipping frontend launch: npm is not installed or not in PATH")
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
if not (self.frontend_dir / "node_modules").exists():
|
|
41
|
+
logger.info("Installing frontend dependencies (npm install)...")
|
|
42
|
+
install = await asyncio.create_subprocess_exec(npm, "install", cwd=str(self.frontend_dir))
|
|
43
|
+
if await install.wait() != 0:
|
|
44
|
+
logger.error("npm install failed with exit code %s", install.returncode)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
logger.info("Starting frontend on http://%s:%s", self.host, self.port)
|
|
48
|
+
self.process = await asyncio.create_subprocess_exec(
|
|
49
|
+
npm, "run", "dev", "--", "--host", self.host, "--port", str(self.port),
|
|
50
|
+
cwd=str(self.frontend_dir),
|
|
51
|
+
# Read by frontend/src/services/useWebSocket.ts
|
|
52
|
+
env={**os.environ, "VITE_GLASSCUBE_WS_PORT": str(self.ws_port)},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
async def stop(self):
|
|
56
|
+
if self.process is None:
|
|
57
|
+
return
|
|
58
|
+
if os.name == "nt":
|
|
59
|
+
# terminate() would only end npm's cmd wrapper and leave Vite holding the port.
|
|
60
|
+
killer = await asyncio.create_subprocess_exec(
|
|
61
|
+
"taskkill", "/T", "/F", "/PID", str(self.process.pid),
|
|
62
|
+
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL,
|
|
63
|
+
)
|
|
64
|
+
await killer.wait()
|
|
65
|
+
else:
|
|
66
|
+
self.process.terminate()
|
|
67
|
+
await self.process.wait()
|
|
68
|
+
self.process = None
|
glasscube/app/main.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Entry point: the `glasscube` command, or `python -m glasscube`."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from ..core import StateManager
|
|
7
|
+
from ..hal import HAL
|
|
8
|
+
from ..server import SmartMirrorServer
|
|
9
|
+
from ..server.static_ui import bundled_ui_dir
|
|
10
|
+
from .frontend_dev import FrontendLauncher
|
|
11
|
+
from .pages import GESTURE_CONFIG, HOME, build_graph
|
|
12
|
+
from .settings import Settings
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def build_assistant(settings, content_sync=None):
|
|
18
|
+
"""The voice chatbot. Ollama-backed by default, so it runs without a paid API key --
|
|
19
|
+
pull a model first (e.g. `ollama pull qwen2.5:0.5b`) and start `ollama serve`.
|
|
20
|
+
|
|
21
|
+
With `content_sync`, it retrieves from the Mongo-derived Qdrant collection and
|
|
22
|
+
gets the live events/announcements prompt block instead of the seed corpus.
|
|
23
|
+
|
|
24
|
+
None when disabled (GLASSCUBE_ASSISTANT=0) or when the `assistant` extra isn't installed.
|
|
25
|
+
"""
|
|
26
|
+
if not settings.assistant:
|
|
27
|
+
return None
|
|
28
|
+
try:
|
|
29
|
+
return _assistant(settings, content_sync)
|
|
30
|
+
except ImportError as error: # the `assistant` extra isn't installed
|
|
31
|
+
logger.warning(
|
|
32
|
+
"Voice assistant off: %s. Install it with `pip install \"glasscube[assistant]\"`, "
|
|
33
|
+
"or set GLASSCUBE_ASSISTANT=0 to hide this.", error,
|
|
34
|
+
)
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _assistant(settings, content_sync):
|
|
39
|
+
from ..assistant import Assistant
|
|
40
|
+
from ..assistant.llm import OpenAICompatBackend
|
|
41
|
+
from ..assistant.rag import SEED_CORPUS_DIR
|
|
42
|
+
|
|
43
|
+
hal = HAL(input_device=settings.mic)
|
|
44
|
+
backend = OpenAICompatBackend(
|
|
45
|
+
api_key=settings.llm_api_key,
|
|
46
|
+
base_url=settings.llm_base_url,
|
|
47
|
+
model=settings.llm_model,
|
|
48
|
+
)
|
|
49
|
+
if content_sync is not None:
|
|
50
|
+
return Assistant(
|
|
51
|
+
llm=backend, stt=True, tts=True, hal=hal,
|
|
52
|
+
store=content_sync.indexer.store,
|
|
53
|
+
extra_context=content_sync.prompt_block,
|
|
54
|
+
)
|
|
55
|
+
return Assistant(llm=backend, documents=str(SEED_CORPUS_DIR), stt=True, tts=True, hal=hal)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def build_content_sync(settings):
|
|
59
|
+
"""Club content from the Dashboard repo's Mongo (glasscube.content); None without MONGO_URI."""
|
|
60
|
+
if not settings.content_mongo_uri:
|
|
61
|
+
return None
|
|
62
|
+
from ..content import build_content_sync as build # needs the `data` extra
|
|
63
|
+
|
|
64
|
+
return build()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def build_server(settings):
|
|
68
|
+
content_sync = build_content_sync(settings)
|
|
69
|
+
state_manager = StateManager(
|
|
70
|
+
graph=build_graph(settings, content_sync),
|
|
71
|
+
initial_node_id=HOME,
|
|
72
|
+
gesture_config=GESTURE_CONFIG,
|
|
73
|
+
)
|
|
74
|
+
return SmartMirrorServer(
|
|
75
|
+
state_manager=state_manager,
|
|
76
|
+
camera_id=settings.camera,
|
|
77
|
+
ws_port=settings.ws_port,
|
|
78
|
+
assistant=build_assistant(settings, content_sync),
|
|
79
|
+
content_sync=content_sync,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def run(server, frontend=None):
|
|
84
|
+
if frontend is not None:
|
|
85
|
+
await frontend.start()
|
|
86
|
+
try:
|
|
87
|
+
await server.run()
|
|
88
|
+
finally:
|
|
89
|
+
if frontend is not None:
|
|
90
|
+
await frontend.stop()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def build_frontend(settings):
|
|
94
|
+
"""The Vite dev server in a checkout with npm; None when the bundled UI is served instead (or turned off)."""
|
|
95
|
+
if not settings.frontend:
|
|
96
|
+
return None
|
|
97
|
+
launcher = FrontendLauncher(port=settings.frontend_port, ws_port=settings.ws_port)
|
|
98
|
+
if launcher.available():
|
|
99
|
+
return launcher
|
|
100
|
+
if bundled_ui_dir() is not None:
|
|
101
|
+
logger.info("Mirror UI on http://localhost:%s", settings.ws_port)
|
|
102
|
+
else:
|
|
103
|
+
logger.warning("No mirror UI: this install has no bundled UI and there's no frontend/ checkout to run.")
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def main():
|
|
108
|
+
# INFO on the glasscube.* loggers surfaces the voice pipeline's play-by-play
|
|
109
|
+
# (VAD, raw Whisper transcripts, wake-word matches; see docs/voice-pipeline-testing.md).
|
|
110
|
+
# Root stays at WARNING so third-party libraries don't drown it out.
|
|
111
|
+
logging.basicConfig(level=logging.WARNING, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
|
112
|
+
logging.getLogger("glasscube").setLevel(logging.INFO)
|
|
113
|
+
|
|
114
|
+
settings = Settings.from_env()
|
|
115
|
+
server = build_server(settings)
|
|
116
|
+
frontend = build_frontend(settings)
|
|
117
|
+
try:
|
|
118
|
+
asyncio.run(run(server, frontend))
|
|
119
|
+
except KeyboardInterrupt:
|
|
120
|
+
pass
|
glasscube/app/pages.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""The mirror's pages and their widgets: draw <-> games <-> home <-> events."""
|
|
2
|
+
|
|
3
|
+
from ..widgets import (
|
|
4
|
+
CalendarWidget,
|
|
5
|
+
DrawingWidget,
|
|
6
|
+
EventsWidget,
|
|
7
|
+
GamesWidget,
|
|
8
|
+
NewsWidget,
|
|
9
|
+
QRGalleryWidget,
|
|
10
|
+
TextWidget,
|
|
11
|
+
WeatherWidget,
|
|
12
|
+
)
|
|
13
|
+
from ..widgets.providers import (
|
|
14
|
+
MongoCalendarProvider,
|
|
15
|
+
OpenMeteoWeatherProvider,
|
|
16
|
+
QRCodeCatalogProvider,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
HOME = "home"
|
|
20
|
+
|
|
21
|
+
GESTURE_CONFIG = {
|
|
22
|
+
"target_radius": 0.40,
|
|
23
|
+
"swipe_cooldown": 0.25,
|
|
24
|
+
"scroll_cooldown": 0.20,
|
|
25
|
+
"node_navigation_cooldown": 0.80,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
QR_CATALOG = {
|
|
29
|
+
"tutorial": [
|
|
30
|
+
{
|
|
31
|
+
"title": "IEEE INSAT CS Social Media",
|
|
32
|
+
"imageUrl": "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://www.facebook.com/INSAT.CS",
|
|
33
|
+
"url": "https://www.facebook.com/INSAT.CS",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
"project": [
|
|
37
|
+
{
|
|
38
|
+
"title": "Smart Mirror SDK",
|
|
39
|
+
"imageUrl": "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://example.com/project/repo",
|
|
40
|
+
"url": "https://github.com/SmartGlassCube",
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def build_graph(settings, content_sync=None):
|
|
47
|
+
"""The page graph for StateManager. `content_sync` (club content from Mongo) feeds
|
|
48
|
+
the calendar, news and events widgets; without it they show placeholders."""
|
|
49
|
+
return {
|
|
50
|
+
"nodes": [
|
|
51
|
+
{"id": HOME, "widgets": home_widgets(settings, content_sync)},
|
|
52
|
+
{"id": "games", "widgets": games_widgets()},
|
|
53
|
+
{"id": "events", "widgets": events_widgets(content_sync)},
|
|
54
|
+
{"id": "draw", "widgets": draw_widgets()},
|
|
55
|
+
],
|
|
56
|
+
"edges": [
|
|
57
|
+
*link(HOME, "games", gesture="two_fingers_swipe_right", back="two_fingers_swipe_left"),
|
|
58
|
+
*link(HOME, "events", gesture="two_fingers_swipe_left", back="two_fingers_swipe_right"),
|
|
59
|
+
*link("games", "draw", gesture="two_fingers_swipe_right", back="two_fingers_swipe_left"),
|
|
60
|
+
],
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def link(page, other, gesture, back):
|
|
65
|
+
"""Edges both ways between two pages: `gesture` goes page -> other, `back` returns."""
|
|
66
|
+
return [
|
|
67
|
+
{"from": page, "to": other, "gesture": gesture},
|
|
68
|
+
{"from": other, "to": page, "gesture": back},
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def home_widgets(settings, content_sync):
|
|
73
|
+
# Live weather for Tunis from Open-Meteo (free, no API key), refreshed every 10 minutes.
|
|
74
|
+
weather = WeatherWidget(
|
|
75
|
+
position={"x": 0.1, "y": 0.2},
|
|
76
|
+
data_provider=OpenMeteoWeatherProvider(city="Tunis", latitude=36.8065, longitude=10.1815),
|
|
77
|
+
refresh_interval=600,
|
|
78
|
+
)
|
|
79
|
+
calendar = CalendarWidget(position={"x": 0.5, "y": 0.2}, refresh_interval=60, **calendar_source(settings, content_sync))
|
|
80
|
+
if content_sync is not None:
|
|
81
|
+
# Active announcements, then achievements, of the SB and its chapters.
|
|
82
|
+
news = NewsWidget(
|
|
83
|
+
position={"x": 0.1, "y": 0.5},
|
|
84
|
+
data_provider=lambda _widget=None: {"items": content_sync.news()},
|
|
85
|
+
refresh_interval=30,
|
|
86
|
+
)
|
|
87
|
+
else:
|
|
88
|
+
news = NewsWidget(position={"x": 0.1, "y": 0.5}, content="Static news placeholder")
|
|
89
|
+
text = TextWidget(
|
|
90
|
+
position={"x": 0.5, "y": 0.5},
|
|
91
|
+
content={
|
|
92
|
+
"home": [
|
|
93
|
+
"Welcome to Smart Mirror!",
|
|
94
|
+
"Swipe left/right for text items",
|
|
95
|
+
"Scroll up/down for sections",
|
|
96
|
+
],
|
|
97
|
+
"focus": [
|
|
98
|
+
"Focus mode activated",
|
|
99
|
+
"Use two fingers and swipe right to go back",
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
qr_gallery = QRGalleryWidget(
|
|
104
|
+
position={"x": 0.8, "y": 0.5},
|
|
105
|
+
content="QR links by category",
|
|
106
|
+
data_provider=QRCodeCatalogProvider(QR_CATALOG),
|
|
107
|
+
refresh_interval=120,
|
|
108
|
+
)
|
|
109
|
+
return [weather, calendar, news, text, qr_gallery]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def calendar_source(settings, content_sync):
|
|
113
|
+
"""The calendar widget's `content` + `data_provider`: club events, a Mongo calendar, or placeholders."""
|
|
114
|
+
if content_sync is not None:
|
|
115
|
+
# The club's events from the dashboard, keyed by day: {"2026-10-28": [event, ...]}.
|
|
116
|
+
return {
|
|
117
|
+
"content": "IEEE INSAT events",
|
|
118
|
+
"data_provider": lambda _widget=None: {"days": content_sync.calendar_days()},
|
|
119
|
+
}
|
|
120
|
+
if settings.calendar_mongo_uri:
|
|
121
|
+
return {
|
|
122
|
+
"content": "Cloud calendar events",
|
|
123
|
+
"data_provider": MongoCalendarProvider(
|
|
124
|
+
uri=settings.calendar_mongo_uri,
|
|
125
|
+
database=settings.calendar_mongo_db,
|
|
126
|
+
collection=settings.calendar_mongo_collection,
|
|
127
|
+
query={},
|
|
128
|
+
),
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
"content": "Fallback local events (set GLASSCUBE_MONGO_READ_URI for cloud)",
|
|
132
|
+
"data_provider": placeholder_calendar,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def placeholder_calendar():
|
|
137
|
+
return {
|
|
138
|
+
"events": [
|
|
139
|
+
{"title": "Standup", "start": "2026-03-15T09:00:00"},
|
|
140
|
+
{"title": "Build Review", "start": "2026-03-15T14:00:00"},
|
|
141
|
+
{"title": "Daily Wrap", "start": "2026-03-15T18:00:00"},
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def games_widgets():
|
|
147
|
+
# Placeholder slots until the computer-vision games exist; give each one an "icon" image URL.
|
|
148
|
+
return [
|
|
149
|
+
GamesWidget(
|
|
150
|
+
position={"x": 0.5, "y": 0.4},
|
|
151
|
+
games=[{"id": f"game-{n}", "title": "Coming soon"} for n in range(1, 7)],
|
|
152
|
+
draggable=False,
|
|
153
|
+
)
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def draw_widgets():
|
|
158
|
+
# The only widget on its page: a pinch anywhere draws instead of grabbing another widget.
|
|
159
|
+
# (0, 0): the frontend keeps widgets on screen, so this pins it to the top-left corner,
|
|
160
|
+
# and the canvas sizes itself to fill the room left by the camera preview and Abdo.
|
|
161
|
+
return [DrawingWidget(position={"x": 0, "y": 0})]
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def events_widgets(content_sync):
|
|
165
|
+
if content_sync is not None:
|
|
166
|
+
# Every event, upcoming then past, with its image (a "?" placeholder without one).
|
|
167
|
+
return [
|
|
168
|
+
EventsWidget(
|
|
169
|
+
position={"x": 0.5, "y": 0.4},
|
|
170
|
+
data_provider=lambda _widget=None: {"items": content_sync.event_cards()},
|
|
171
|
+
refresh_interval=30,
|
|
172
|
+
draggable=False,
|
|
173
|
+
)
|
|
174
|
+
]
|
|
175
|
+
# Placeholder cards until MONGO_URI is set.
|
|
176
|
+
return [
|
|
177
|
+
EventsWidget(
|
|
178
|
+
position={"x": 0.5, "y": 0.4},
|
|
179
|
+
items=[
|
|
180
|
+
{"id": f"event-{n}", "name": "Event name", "description": "Description from the club database."}
|
|
181
|
+
for n in range(1, 4)
|
|
182
|
+
],
|
|
183
|
+
draggable=False,
|
|
184
|
+
)
|
|
185
|
+
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""The mirror app's settings: environment variables, plus a .env file when python-dotenv is installed
|
|
2
|
+
(./.env in the working directory, then backend/.env in a checkout of the repo).
|
|
3
|
+
|
|
4
|
+
See backend/.env.example for every variable.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Optional, Union
|
|
11
|
+
|
|
12
|
+
from ..config.env import adopt_legacy_env
|
|
13
|
+
from ..config.paths import CHECKOUT_BACKEND_DIR
|
|
14
|
+
|
|
15
|
+
# A camera/microphone: None (the default device), a local device index, or an
|
|
16
|
+
# http:// URL served by scripts/lan_media_server.py on another machine.
|
|
17
|
+
Device = Union[int, str, None]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def device_from_env(name: str) -> Device:
|
|
21
|
+
value = os.getenv(name, "").strip()
|
|
22
|
+
if not value:
|
|
23
|
+
return None
|
|
24
|
+
return int(value) if value.isdigit() else value
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def flag_from_env(name: str, default: bool) -> bool:
|
|
28
|
+
value = os.getenv(name, "").strip().lower()
|
|
29
|
+
if not value:
|
|
30
|
+
return default
|
|
31
|
+
return value not in ("0", "false", "no", "off")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def load_dotenv_file() -> None:
|
|
35
|
+
"""Load ./.env, then backend/.env in a checkout, into os.environ.
|
|
36
|
+
|
|
37
|
+
Variables already set win, and so does the first file. No-op without python-dotenv.
|
|
38
|
+
"""
|
|
39
|
+
try:
|
|
40
|
+
from dotenv import load_dotenv
|
|
41
|
+
except ImportError:
|
|
42
|
+
return
|
|
43
|
+
load_dotenv(Path.cwd() / ".env")
|
|
44
|
+
if CHECKOUT_BACKEND_DIR is not None:
|
|
45
|
+
load_dotenv(CHECKOUT_BACKEND_DIR / ".env")
|
|
46
|
+
adopt_legacy_env() # a .env written before the rename still uses SMARTMIRROR_*
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class Settings:
|
|
51
|
+
camera: Device = 0
|
|
52
|
+
mic: Device = None
|
|
53
|
+
|
|
54
|
+
# Any OpenAI-compatible endpoint; Ollama by default, so no paid API key is needed.
|
|
55
|
+
llm_base_url: str = "http://localhost:11434/v1"
|
|
56
|
+
llm_model: str = "qwen2.5:0.5b"
|
|
57
|
+
llm_api_key: str = "ollama"
|
|
58
|
+
|
|
59
|
+
# MONGO_URI: the IEEE INSAT club content (events, news, ...) from the Dashboard repo's Mongo.
|
|
60
|
+
content_mongo_uri: Optional[str] = None
|
|
61
|
+
# GLASSCUBE_MONGO_READ_URI: a generic calendar collection, used when there's no club content.
|
|
62
|
+
calendar_mongo_uri: Optional[str] = None
|
|
63
|
+
calendar_mongo_db: str = "smartmirror" # existing deployments keep their database
|
|
64
|
+
calendar_mongo_collection: str = "events"
|
|
65
|
+
|
|
66
|
+
# The voice assistant; it also needs the `assistant` extra (skipped with a warning without it).
|
|
67
|
+
assistant: bool = True
|
|
68
|
+
|
|
69
|
+
ws_port: int = 8080
|
|
70
|
+
# In a checkout, start the frontend's Vite dev server along with the backend (dev convenience).
|
|
71
|
+
# Otherwise the bundled, prebuilt UI is served on ws_port: http://localhost:8080.
|
|
72
|
+
frontend: bool = True
|
|
73
|
+
frontend_port: int = 5173
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_env(cls) -> "Settings":
|
|
77
|
+
load_dotenv_file()
|
|
78
|
+
defaults = cls()
|
|
79
|
+
return cls(
|
|
80
|
+
camera=device_from_env("GLASSCUBE_CAMERA") or defaults.camera,
|
|
81
|
+
mic=device_from_env("GLASSCUBE_MIC"),
|
|
82
|
+
llm_base_url=os.getenv("GLASSCUBE_LLM_BASE_URL", defaults.llm_base_url),
|
|
83
|
+
llm_model=os.getenv("GLASSCUBE_LLM_MODEL", defaults.llm_model),
|
|
84
|
+
llm_api_key=os.getenv("GLASSCUBE_LLM_API_KEY", defaults.llm_api_key),
|
|
85
|
+
content_mongo_uri=os.getenv("MONGO_URI") or None,
|
|
86
|
+
calendar_mongo_uri=os.getenv("GLASSCUBE_MONGO_READ_URI") or None,
|
|
87
|
+
calendar_mongo_db=os.getenv("GLASSCUBE_MONGO_DB", defaults.calendar_mongo_db),
|
|
88
|
+
calendar_mongo_collection=os.getenv("GLASSCUBE_MONGO_COLLECTION", defaults.calendar_mongo_collection),
|
|
89
|
+
assistant=flag_from_env("GLASSCUBE_ASSISTANT", defaults.assistant),
|
|
90
|
+
ws_port=int(os.getenv("GLASSCUBE_WS_PORT", defaults.ws_port)),
|
|
91
|
+
frontend=flag_from_env("GLASSCUBE_FRONTEND", defaults.frontend),
|
|
92
|
+
frontend_port=int(os.getenv("GLASSCUBE_FRONTEND_PORT", defaults.frontend_port)),
|
|
93
|
+
)
|