Repository navigation
Expand file tree
/
Copy pathscreen_reader.py
More file actions
68 lines (54 loc) · 1.85 KB
/
Copy pathscreen_reader.py
File metadata and controls
68 lines (54 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""
screen_reader.py — ScreenKitTY main orchestration loop (standalone).
python3 screen_reader.py
Runs on the main thread and drives the full loop:
screenshot → Gemma → dispatch via ScreenUI → block for user → repeat
Session logic lives in screen_ui.run_session(). This file is just the
entry point: preload Gemma, construct ScreenUI, loop until dismiss.
"""
from __future__ import annotations
import sys
import threading
import time
import traceback
from screen_ui import ScreenUI, run_session
from screenkitty.pipeline import get_inference_engine
def _preload_gemma() -> None:
"""Warm the inference engine in the background — first session becomes fast."""
try:
get_inference_engine().load_model()
print("[preload] Gemma ready")
except Exception as exc:
print(f"[preload] Gemma load failed: {exc}")
def main() -> int:
print("=" * 60)
print(" ScreenKitTY — screen reader for visually impaired users")
print("=" * 60)
print(" Tab — cycle options")
print(" Return — select")
print(" Escape — back / dismiss")
print(" Ctrl+C — quit")
print("=" * 60)
print()
threading.Thread(target=_preload_gemma, daemon=True).start()
ui = ScreenUI(announce_on_startup=True)
try:
while True:
print()
print("[main] ────────── new session ──────────")
keep_going = run_session(ui)
if not keep_going:
return 0
time.sleep(0.3)
except KeyboardInterrupt:
print("\n[main] interrupted")
ui.announce("Goodbye.")
time.sleep(0.4)
return 0
except Exception as exc:
print(f"[main] fatal: {exc}")
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())