omnipython-apps 0.1.4.dev8__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.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/huey/acting.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Read what the chat model sent back: what Huey says, and how he acts it out.
|
|
5
|
+
|
|
6
|
+
The model is asked for one JSON object, ``{"say": "...", "mood": "happy",
|
|
7
|
+
"colors": "sunset", "prop": "mug", "place": "coast", "variant": "winter"}``,
|
|
8
|
+
where everything but ``say`` is optional. `read` takes whatever came back.
|
|
9
|
+
A model that wrote plain words is taken at its word, and a mood, a colour,
|
|
10
|
+
a prop or a place that Huey doesn't have is left out and noted.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
from .actor import COLORS, MOODS, PROPS, VARIANTS
|
|
16
|
+
|
|
17
|
+
#: The most of a reply that is spoken and shown, in characters.
|
|
18
|
+
SAY_MOST = 280
|
|
19
|
+
|
|
20
|
+
PROMPT = (
|
|
21
|
+
"You are Huey, a small, warm, curious chameleon (he, him) who lives on a little screen on someone's desk. "
|
|
22
|
+
"They talk to you out loud and hear your answer spoken. Answer the way a friend would across a desk: "
|
|
23
|
+
"one or two short sentences of plain spoken words, with no lists, no markdown and no emoji.\n"
|
|
24
|
+
'Reply with one JSON object and nothing else. It always has "say", the words you speak. '
|
|
25
|
+
"You are a chameleon on a stage, so when it suits what you say, act it out with any of these keys:\n"
|
|
26
|
+
'"mood": %s\n'
|
|
27
|
+
'"colors", the colours you turn: %s\n'
|
|
28
|
+
'"prop", something to hold up: %s\n'
|
|
29
|
+
'"place", somewhere to go: %s\n'
|
|
30
|
+
'"variant", the season at the coast (%s) or the time of day at the desk (%s)\n'
|
|
31
|
+
"Use a key only to change something, and leave the rest out. For example, asked which season you like best:\n"
|
|
32
|
+
'{"say": "Autumn, easily. Watch, I turn the colour of the leaves.", "mood": "happy", "place": "coast", "variant": "autumn"}\n'
|
|
33
|
+
"and asked what two and two make:\n"
|
|
34
|
+
'{"say": "Four. I counted on my toes."}\n'
|
|
35
|
+
"Just now you are at the %s%s, and your colours are %s."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def prompt(place, variant, colors):
|
|
40
|
+
"""The system message: who Huey is, the reply's format, and where he is now."""
|
|
41
|
+
return PROMPT % (
|
|
42
|
+
", ".join(MOODS),
|
|
43
|
+
", ".join(COLORS),
|
|
44
|
+
", ".join(PROPS),
|
|
45
|
+
", ".join(sorted(VARIANTS)),
|
|
46
|
+
", ".join(VARIANTS["coast"]),
|
|
47
|
+
", ".join(VARIANTS["desk"]),
|
|
48
|
+
place,
|
|
49
|
+
" (%s)" % variant if VARIANTS[place] else "",
|
|
50
|
+
colors,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Act:
|
|
55
|
+
"""One reply: `say`, and the `mood`, `colors`, `prop`, `place` and `variant` it chose, each None when it chose none.
|
|
56
|
+
|
|
57
|
+
`ignored` lists what the model asked for that Huey doesn't have, as
|
|
58
|
+
``(key, value)`` pairs.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, say):
|
|
62
|
+
self.say = say
|
|
63
|
+
self.mood = self.colors = self.prop = self.place = self.variant = None
|
|
64
|
+
self.ignored = []
|
|
65
|
+
|
|
66
|
+
def record(self):
|
|
67
|
+
"""The reply as the model should have written it, for the history it is shown."""
|
|
68
|
+
# "say" first, as the model is asked to write it: a dict's order isn't kept everywhere
|
|
69
|
+
out = ['"say": ' + json.dumps(self.say)]
|
|
70
|
+
for key in ("mood", "colors", "prop", "place", "variant"):
|
|
71
|
+
if getattr(self, key) is not None:
|
|
72
|
+
out.append('"%s": %s' % (key, json.dumps(getattr(self, key))))
|
|
73
|
+
return "{" + ", ".join(out) + "}"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _object(text):
|
|
77
|
+
"""The JSON object in *text*, or None: alone, in a code fence, or among other words."""
|
|
78
|
+
start = text.find("{")
|
|
79
|
+
end = text.rfind("}")
|
|
80
|
+
if start < 0 or end <= start:
|
|
81
|
+
return None
|
|
82
|
+
try:
|
|
83
|
+
found = json.loads(text[start : end + 1])
|
|
84
|
+
except ValueError:
|
|
85
|
+
return None
|
|
86
|
+
return found if isinstance(found, dict) else None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _plain(text):
|
|
90
|
+
"""Words written for the eye made fit to say: no fences, stars or quotes round them."""
|
|
91
|
+
text = text.replace("```json", " ").replace("```", " ").replace("**", "").replace("*", "")
|
|
92
|
+
text = " ".join(text.split())
|
|
93
|
+
if len(text) > 1 and text[0] == text[-1] and text[0] in "\"'":
|
|
94
|
+
text = text[1:-1]
|
|
95
|
+
return text
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _clip(text):
|
|
99
|
+
if len(text) <= SAY_MOST:
|
|
100
|
+
return text
|
|
101
|
+
cut = text[:SAY_MOST]
|
|
102
|
+
for stop in (". ", "! ", "? "):
|
|
103
|
+
at = cut.rfind(stop)
|
|
104
|
+
if at > SAY_MOST // 3:
|
|
105
|
+
return cut[: at + 1]
|
|
106
|
+
return cut.rsplit(" ", 1)[0] + "..."
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def words(say):
|
|
110
|
+
"""The words Huey speaks for the model's *say*: what `read` gives as an act's ``say``."""
|
|
111
|
+
return _clip(_plain(say))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def early(text):
|
|
115
|
+
"""The words of a reply still arriving, once its ``say`` is complete, or None until then.
|
|
116
|
+
|
|
117
|
+
This is the reply as `read` would take it if *text* is the JSON object
|
|
118
|
+
it was asked for, so speech can be asked for before the rest arrives.
|
|
119
|
+
"""
|
|
120
|
+
start = text.lstrip()
|
|
121
|
+
if start.startswith("```"):
|
|
122
|
+
start = start[3:].lstrip("json \t\r\n")
|
|
123
|
+
at = text.find('"say"')
|
|
124
|
+
if at < 0 or start[:1] != "{":
|
|
125
|
+
return None
|
|
126
|
+
at += 5
|
|
127
|
+
while at < len(text) and text[at] in " \t\r\n:":
|
|
128
|
+
at += 1
|
|
129
|
+
if at >= len(text) or text[at] != '"':
|
|
130
|
+
return None
|
|
131
|
+
end = at + 1
|
|
132
|
+
while True:
|
|
133
|
+
end = text.find('"', end)
|
|
134
|
+
if end < 0:
|
|
135
|
+
return None
|
|
136
|
+
back = end - 1
|
|
137
|
+
while text[back] == "\\":
|
|
138
|
+
back -= 1
|
|
139
|
+
if (end - 1 - back) % 2 == 0:
|
|
140
|
+
break # not escaped
|
|
141
|
+
end += 1
|
|
142
|
+
try:
|
|
143
|
+
say = json.loads(text[at : end + 1])
|
|
144
|
+
except ValueError:
|
|
145
|
+
return None
|
|
146
|
+
return words(say) or None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def read(text, place):
|
|
150
|
+
"""Make an `Act` of the model's reply *text*, given the *place* Huey is in.
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
ValueError: The reply has nothing to say.
|
|
154
|
+
"""
|
|
155
|
+
found = _object(text)
|
|
156
|
+
if found is None:
|
|
157
|
+
say = _plain(text)
|
|
158
|
+
if say.startswith("{"):
|
|
159
|
+
# an object cut short: its words are still worth having
|
|
160
|
+
at = say.find('"say"')
|
|
161
|
+
say = say[at + 5 :].lstrip(' :"').split('"')[0] if at >= 0 else ""
|
|
162
|
+
found = {}
|
|
163
|
+
else:
|
|
164
|
+
say = found.get("say")
|
|
165
|
+
say = _plain(say) if isinstance(say, str) else ""
|
|
166
|
+
if not say:
|
|
167
|
+
raise ValueError("the reply had nothing to say")
|
|
168
|
+
act = Act(words(say))
|
|
169
|
+
|
|
170
|
+
def choose(key, allowed):
|
|
171
|
+
value = found.get(key)
|
|
172
|
+
if value is None or value == "" or value == "none":
|
|
173
|
+
return None
|
|
174
|
+
if isinstance(value, str) and value.lower() in allowed:
|
|
175
|
+
return value.lower()
|
|
176
|
+
act.ignored.append((key, value))
|
|
177
|
+
return None
|
|
178
|
+
|
|
179
|
+
act.mood = choose("mood", MOODS)
|
|
180
|
+
act.colors = choose("colors", COLORS)
|
|
181
|
+
act.prop = choose("prop", PROPS)
|
|
182
|
+
act.place = choose("place", VARIANTS)
|
|
183
|
+
act.variant = choose("variant", VARIANTS[act.place or place])
|
|
184
|
+
return act
|
apps/huey/actor.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Huey as someone to talk to: Perch's stage, with poses for a conversation.
|
|
5
|
+
|
|
6
|
+
`Actor` is Perch's `Stage` with four more things for the chameleon to do. He
|
|
7
|
+
turns to face you while he listens, his eyes wander while he thinks, his
|
|
8
|
+
mouth moves while he speaks, and then he settles back into the life he leads
|
|
9
|
+
in Perch. `perform` takes what a reply asked for: colours, a place, a season.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import lvgl as lv
|
|
13
|
+
|
|
14
|
+
from ..perch import huey, huey_shift # noqa: F401 (huey_shift adds the rest of the colours)
|
|
15
|
+
from ..perch.huey_props import ORDER as PROPS
|
|
16
|
+
from ..perch.stage import _BODY, _REACH, PLACES, Stage
|
|
17
|
+
|
|
18
|
+
MOODS = ("calm", "happy", "curious", "sleepy")
|
|
19
|
+
COLORS = ("leaf", "brand", "sunset", "board", "blossom", "snow", "night", "copper")
|
|
20
|
+
#: Each place a reply may ask for, and the seasons or times of day it has.
|
|
21
|
+
#: The workbench has none: there the colours are the only thing to change.
|
|
22
|
+
VARIANTS = {
|
|
23
|
+
"coast": PLACES["coast"]["variants"],
|
|
24
|
+
"bench": (),
|
|
25
|
+
"desk": PLACES["desk"]["variants"],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_THINKS = (
|
|
29
|
+
((-0.4, -0.9), (0.8, -0.5), -8, 1.0),
|
|
30
|
+
((0.7, -0.8), (-0.6, -0.7), -10, 0.6),
|
|
31
|
+
)
|
|
32
|
+
_OPEN = (140, -110) # inside his mouth: where the tongue rests while he speaks
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Actor(Stage):
|
|
36
|
+
"""Perch's stage, and the chameleon playing a part in a conversation.
|
|
37
|
+
|
|
38
|
+
`listen`, `think`, `speak` and `settle` say what he is doing. While he
|
|
39
|
+
speaks, set `mouth` to True and False as the sound rises and falls.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, root, size, place="desk", variant=None, view="wide", seed=7):
|
|
43
|
+
#: "idle", "listen", "think", "speak" or "settle".
|
|
44
|
+
self.part = "idle"
|
|
45
|
+
#: True while his mouth is open, as he speaks.
|
|
46
|
+
self.mouth = False
|
|
47
|
+
self.mood = "calm"
|
|
48
|
+
self.prop = None
|
|
49
|
+
Stage.__init__(self, root, size, place, variant, view, seed)
|
|
50
|
+
|
|
51
|
+
def shapes(self, doc, spec, scheme):
|
|
52
|
+
kind = spec[0]
|
|
53
|
+
if kind == "think":
|
|
54
|
+
look, far, nod, curl = _THINKS[spec[1]]
|
|
55
|
+
return huey.draw(doc, look=look, look_far=far, mood="curious", nod=nod, curl=curl, colors=scheme, perch=None), _REACH
|
|
56
|
+
if kind == "talk":
|
|
57
|
+
mood, is_open = spec[1], spec[2]
|
|
58
|
+
if mood == "happy":
|
|
59
|
+
return huey.draw(doc, look=(0.2, 0.0), mood="happy" if is_open else "calm", colors=scheme, perch=None), _BODY
|
|
60
|
+
if is_open:
|
|
61
|
+
eyes = "sleepy" if mood == "sleepy" else "calm"
|
|
62
|
+
return huey.draw(doc, look=(0.2, 0.0), mood=eyes, tongue=1, target=_OPEN, colors=scheme, perch=None), _BODY
|
|
63
|
+
return huey.draw(doc, look=(0.2, 0.0), mood=mood, colors=scheme, perch=None), _REACH
|
|
64
|
+
return Stage.shapes(self, doc, spec, scheme)
|
|
65
|
+
|
|
66
|
+
# -- the parts he plays ----------------------------------------------
|
|
67
|
+
|
|
68
|
+
def _play(self, part):
|
|
69
|
+
self.part = part
|
|
70
|
+
self.mouth = False
|
|
71
|
+
if self._loader is None:
|
|
72
|
+
self._life = self._live()
|
|
73
|
+
self._wait = 0
|
|
74
|
+
self._quiet = False
|
|
75
|
+
self.bug.add_flag(lv.obj.FLAG.HIDDEN)
|
|
76
|
+
|
|
77
|
+
def listen(self):
|
|
78
|
+
"""He turns to face you, and keeps still."""
|
|
79
|
+
self._play("listen")
|
|
80
|
+
|
|
81
|
+
def think(self):
|
|
82
|
+
"""His eyes wander, each its own way, until there is something to say."""
|
|
83
|
+
self._play("think")
|
|
84
|
+
|
|
85
|
+
def speak(self, mood="calm", prop=None):
|
|
86
|
+
"""He speaks in *mood*, holding *prop* if one is named; `mouth` moves his mouth."""
|
|
87
|
+
self.mood = mood
|
|
88
|
+
self.prop = prop
|
|
89
|
+
self._play("speak")
|
|
90
|
+
|
|
91
|
+
def settle(self):
|
|
92
|
+
"""He holds his last look a moment, then goes back to his own life."""
|
|
93
|
+
if self.part != "idle":
|
|
94
|
+
self._play("settle")
|
|
95
|
+
|
|
96
|
+
def rest(self):
|
|
97
|
+
"""Back to his own life at once."""
|
|
98
|
+
self._play("idle")
|
|
99
|
+
|
|
100
|
+
def _talking(self):
|
|
101
|
+
"""The two pictures he speaks with: mouth closed, mouth open."""
|
|
102
|
+
if self.prop:
|
|
103
|
+
return ("hold", self.prop, 0), ("hold", self.prop, 1)
|
|
104
|
+
return ("talk", self.mood, 0), ("talk", self.mood, 1)
|
|
105
|
+
|
|
106
|
+
def _live(self):
|
|
107
|
+
if self.part == "idle":
|
|
108
|
+
return Stage._live(self)
|
|
109
|
+
return self._perform()
|
|
110
|
+
|
|
111
|
+
def _perform(self):
|
|
112
|
+
while self.part != "idle":
|
|
113
|
+
part = self.part
|
|
114
|
+
self._quiet = False
|
|
115
|
+
if self._facing < 0:
|
|
116
|
+
# the poses of a conversation are drawn facing right
|
|
117
|
+
self._facing = 1
|
|
118
|
+
if part == "listen":
|
|
119
|
+
if not (yield from self._ready(("front", 0, 0), ("front", 0, 1))):
|
|
120
|
+
yield 1
|
|
121
|
+
continue
|
|
122
|
+
beat = 0
|
|
123
|
+
while self.part == "listen":
|
|
124
|
+
beat += 1
|
|
125
|
+
self._show(("front", 0, 1 if beat % 90 == 60 else 0))
|
|
126
|
+
yield 3 if beat % 90 == 60 else 1
|
|
127
|
+
elif part == "think":
|
|
128
|
+
first, second = ("think", 0), ("think", 1)
|
|
129
|
+
if not (yield from self._ready(first)):
|
|
130
|
+
yield 1
|
|
131
|
+
continue
|
|
132
|
+
self._show(first)
|
|
133
|
+
self._wanted.insert(0, second)
|
|
134
|
+
beat = 0
|
|
135
|
+
while self.part == "think":
|
|
136
|
+
beat += 1
|
|
137
|
+
if beat % 28 == 0 and self._have(second):
|
|
138
|
+
self._show(second if self.pose == first else first)
|
|
139
|
+
yield 1
|
|
140
|
+
elif part == "speak":
|
|
141
|
+
shut, wide = self._talking()
|
|
142
|
+
if not (yield from self._ready(shut, wide)):
|
|
143
|
+
yield 1
|
|
144
|
+
continue
|
|
145
|
+
while self.part == "speak":
|
|
146
|
+
self._show(wide if self.mouth else shut)
|
|
147
|
+
yield 1
|
|
148
|
+
elif part == "settle":
|
|
149
|
+
last = ("happy",) if self.mood == "happy" and not self.prop else self._talking()[0]
|
|
150
|
+
if (yield from self._ready(last)):
|
|
151
|
+
self._show(last)
|
|
152
|
+
for _ in range(40):
|
|
153
|
+
if self.part != "settle":
|
|
154
|
+
break
|
|
155
|
+
yield 1
|
|
156
|
+
if self.part == "settle":
|
|
157
|
+
self.part = "idle"
|
|
158
|
+
self._life = Stage._live(self)
|
|
159
|
+
yield 1
|
|
160
|
+
|
|
161
|
+
def _change(self, place, variant, view):
|
|
162
|
+
yield from Stage._change(self, place, variant, view)
|
|
163
|
+
# what a conversation opens with, drawn before it is wanted
|
|
164
|
+
self._wanted[:0] = [("front", 0, 0), ("front", 0, 1), ("think", 0)]
|
|
165
|
+
|
|
166
|
+
# -- what a reply asked for ------------------------------------------
|
|
167
|
+
|
|
168
|
+
def perform(self, colors=None, place=None, variant=None):
|
|
169
|
+
"""Put on *colors*, go to *place*, change to *variant*: each only when given.
|
|
170
|
+
|
|
171
|
+
A place or a season given without colours brings that place's own
|
|
172
|
+
colours back. Nothing happens while an earlier change is being drawn.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
True when a change was begun.
|
|
176
|
+
"""
|
|
177
|
+
if colors is None and place is None and variant is None:
|
|
178
|
+
return False
|
|
179
|
+
if self._loader is not None:
|
|
180
|
+
return False
|
|
181
|
+
if colors is not None:
|
|
182
|
+
self.wears = colors
|
|
183
|
+
else:
|
|
184
|
+
self.wears = None
|
|
185
|
+
place = place or self.place
|
|
186
|
+
if variant is None and place == self.place:
|
|
187
|
+
variant = self.variant
|
|
188
|
+
if (place, variant or PLACES[place]["variants"][0]) == (self.place, self.variant) and (self.wears or self._own()) == self.scheme:
|
|
189
|
+
return False
|
|
190
|
+
return self.go(place, variant)
|
|
191
|
+
|
|
192
|
+
def _own(self):
|
|
193
|
+
schemes = PLACES[self.place]["schemes"]
|
|
194
|
+
return schemes[self.variant] if schemes else self.variant
|
apps/huey/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "huey", "title": "Huey", "category": "Desk", "icon": "record_voice_over", "color": "#3E9440", "needs": ["svgio.expand", "svgio.Buffer", "socket", "_thread"]}
|
apps/huey/client.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Talk to an OpenAI-compatible server: speech to text, a chat reply, text to speech.
|
|
5
|
+
|
|
6
|
+
`Client` makes the three calls a turn needs, ``audio/transcriptions``,
|
|
7
|
+
``chat/completions`` and ``audio/speech``, against the address and models in
|
|
8
|
+
the app's settings. Every call blocks: make it from a worker.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
import chatclient
|
|
14
|
+
from chatclient import Chat, ServerError, web # noqa: F401 - Huey's names for them
|
|
15
|
+
|
|
16
|
+
_EDGE = "huey-speech-edge-7c1f"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def wav_header(size, rate, channels=1):
|
|
20
|
+
"""The 44 bytes that go before *size* bytes of 16-bit PCM to make a WAV file."""
|
|
21
|
+
block = channels * 2
|
|
22
|
+
head = bytearray(b"RIFF\x00\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00")
|
|
23
|
+
head[4:8] = (36 + size).to_bytes(4, "little")
|
|
24
|
+
head += channels.to_bytes(2, "little") + rate.to_bytes(4, "little") + (rate * block).to_bytes(4, "little")
|
|
25
|
+
head += block.to_bytes(2, "little") + b"\x10\x00data" + size.to_bytes(4, "little")
|
|
26
|
+
return bytes(head)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Speech:
|
|
30
|
+
"""Speech on its way from the server: its `rate` and `channels`, and 16-bit PCM through `read`."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, reply, rate):
|
|
33
|
+
self._reply = reply
|
|
34
|
+
self._held = b""
|
|
35
|
+
self.rate = rate
|
|
36
|
+
self.channels = 1
|
|
37
|
+
first = self._exactly(12)
|
|
38
|
+
if first[:4] != b"RIFF":
|
|
39
|
+
kind = reply.headers.get("content-type", "")
|
|
40
|
+
if "pcm" not in kind and "octet-stream" not in kind and "l16" not in kind.lower():
|
|
41
|
+
raise ValueError("the speech came as %s, not as WAV or PCM" % (kind or "something unnamed"))
|
|
42
|
+
# bare PCM, at the rate the settings give
|
|
43
|
+
self._held = first
|
|
44
|
+
return
|
|
45
|
+
while True:
|
|
46
|
+
name_size = self._exactly(8)
|
|
47
|
+
size = int.from_bytes(name_size[4:8], "little")
|
|
48
|
+
if name_size[:4] == b"data":
|
|
49
|
+
return
|
|
50
|
+
chunk = self._exactly(size + (size & 1))
|
|
51
|
+
if name_size[:4] == b"fmt ":
|
|
52
|
+
if chunk[0:2] != b"\x01\x00" or chunk[14:16] != b"\x10\x00":
|
|
53
|
+
raise ValueError("the speech isn't 16-bit PCM")
|
|
54
|
+
self.channels = int.from_bytes(chunk[2:4], "little")
|
|
55
|
+
self.rate = int.from_bytes(chunk[4:8], "little")
|
|
56
|
+
|
|
57
|
+
def _exactly(self, size):
|
|
58
|
+
parts = []
|
|
59
|
+
while size > 0:
|
|
60
|
+
data = self._reply.read(size)
|
|
61
|
+
if not data:
|
|
62
|
+
raise ValueError("the speech ended inside its header")
|
|
63
|
+
parts.append(data)
|
|
64
|
+
size -= len(data)
|
|
65
|
+
return b"".join(parts)
|
|
66
|
+
|
|
67
|
+
def read(self, size):
|
|
68
|
+
"""Up to *size* bytes of sound, and ``b""`` at the end."""
|
|
69
|
+
if self._held:
|
|
70
|
+
data, self._held = self._held, b""
|
|
71
|
+
return data
|
|
72
|
+
return self._reply.read(size)
|
|
73
|
+
|
|
74
|
+
def close(self):
|
|
75
|
+
self._reply.close()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Client(chatclient.Client):
|
|
79
|
+
"""The three calls of a turn, against one server.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
settings (dict): ``base_url``, the three models, ``voice`` and
|
|
83
|
+
``speech_rate``, as `settings.load` gives them.
|
|
84
|
+
key (str): The API key, or ``""`` for a server that asks for none.
|
|
85
|
+
post: What sends a request; `web.post` unless a test gives its own.
|
|
86
|
+
speech_post: What sends the request for speech, when it isn't
|
|
87
|
+
*post*: speech can be asked for while a reply still arrives.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(self, settings, key, post=web.post, speech_post=None):
|
|
91
|
+
chatclient.Client.__init__(self, settings["base_url"], key, post)
|
|
92
|
+
self.settings = settings
|
|
93
|
+
self._speech_post = speech_post or post
|
|
94
|
+
|
|
95
|
+
def transcribe(self, pcm, rate):
|
|
96
|
+
"""The words in *pcm*, 16-bit mono sound at *rate*, as text."""
|
|
97
|
+
head = (
|
|
98
|
+
'--%s\r\nContent-Disposition: form-data; name="model"\r\n\r\n%s\r\n'
|
|
99
|
+
'--%s\r\nContent-Disposition: form-data; name="response_format"\r\n\r\njson\r\n'
|
|
100
|
+
'--%s\r\nContent-Disposition: form-data; name="file"; filename="speech.wav"\r\n'
|
|
101
|
+
"Content-Type: audio/wav\r\n\r\n"
|
|
102
|
+
) % (_EDGE, self.settings["stt_model"], _EDGE, _EDGE)
|
|
103
|
+
pieces = [head.encode(), wav_header(len(pcm), rate), pcm, ("\r\n--%s--\r\n" % _EDGE).encode()]
|
|
104
|
+
found = self._json("/audio/transcriptions", {"Content-Type": "multipart/form-data; boundary=" + _EDGE}, pieces, 60)
|
|
105
|
+
return found["text"].strip()
|
|
106
|
+
|
|
107
|
+
def chat(self, messages):
|
|
108
|
+
"""The model's reply to *messages*, as text."""
|
|
109
|
+
return chatclient.Client.chat(self, messages, self.settings["chat_model"], max_tokens=200, temperature=0.7)
|
|
110
|
+
|
|
111
|
+
def chat_stream(self, messages):
|
|
112
|
+
"""The model's reply to *messages* as a `Chat`, to read as it arrives."""
|
|
113
|
+
return chatclient.Client.chat_stream(self, messages, self.settings["chat_model"], max_tokens=200, temperature=0.7)
|
|
114
|
+
|
|
115
|
+
def speak(self, text):
|
|
116
|
+
"""*text* as speech: a `Speech` to read and then close."""
|
|
117
|
+
body = {"model": self.settings["tts_model"], "input": text, "response_format": "wav"}
|
|
118
|
+
if self.settings["voice"]:
|
|
119
|
+
body["voice"] = self.settings["voice"]
|
|
120
|
+
reply = self._send("/audio/speech", {"Content-Type": "application/json"}, [json.dumps(body).encode()], 60, self._speech_post)
|
|
121
|
+
try:
|
|
122
|
+
return Speech(reply, self.settings["speech_rate"])
|
|
123
|
+
except Exception:
|
|
124
|
+
reply.close()
|
|
125
|
+
raise
|
apps/huey/servers.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Huey's servers in the device's picker, under Assistant.
|
|
5
|
+
|
|
6
|
+
The server in Huey's settings, and each one in their ``servers`` list, is an
|
|
7
|
+
endpoint of endpointkit's ``assistant`` kind. Choose one in the picker and
|
|
8
|
+
Huey talks to it from his next turn, with its models, voice and key. The
|
|
9
|
+
choice is the device's, so another app that talks to an assistant can
|
|
10
|
+
follow it too. Without endpointkit installed, Huey uses the server in his
|
|
11
|
+
settings, as before.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
import endpointkit
|
|
16
|
+
except ImportError:
|
|
17
|
+
endpointkit = None
|
|
18
|
+
|
|
19
|
+
from .settings import SERVER_KEYS
|
|
20
|
+
|
|
21
|
+
#: The provider's name: the first half of each endpoint's id.
|
|
22
|
+
NAME = "huey"
|
|
23
|
+
#: The local id of the server the settings give at their top level.
|
|
24
|
+
OWN = "settings"
|
|
25
|
+
#: The endpoint caps that say where an assistant is; other providers' endpoints
|
|
26
|
+
#: of the kind give these too, so Huey can follow any of them.
|
|
27
|
+
CAPS = SERVER_KEYS
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _slug(name):
|
|
31
|
+
out = ""
|
|
32
|
+
for ch in name.lower():
|
|
33
|
+
out += ch if ("a" <= ch <= "z" or "0" <= ch <= "9") else "-"
|
|
34
|
+
return out.strip("-") or "server"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _where(base_url):
|
|
38
|
+
"""The host of *base_url*: "api.deepinfra.com", "192.168.1.20:5000"."""
|
|
39
|
+
rest = base_url.split("://", 1)[-1]
|
|
40
|
+
return rest.split("/", 1)[0]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def entries(settings):
|
|
44
|
+
"""``(local_id, label, caps)`` for each server *settings* give: their own
|
|
45
|
+
first, when it has an address, then each of ``servers``."""
|
|
46
|
+
out = []
|
|
47
|
+
if settings["base_url"]:
|
|
48
|
+
caps = {k: settings[k] for k in CAPS}
|
|
49
|
+
out.append((OWN, _where(settings["base_url"]), caps))
|
|
50
|
+
taken = [OWN]
|
|
51
|
+
for server in settings["servers"]:
|
|
52
|
+
local = _slug(server["name"])
|
|
53
|
+
n = 2
|
|
54
|
+
while local in taken:
|
|
55
|
+
local = "%s-%d" % (_slug(server["name"]), n)
|
|
56
|
+
n += 1
|
|
57
|
+
taken.append(local)
|
|
58
|
+
caps = {k: settings[k] for k in CAPS}
|
|
59
|
+
caps.update({k: v for k, v in server.items() if k != "name"})
|
|
60
|
+
out.append((local, server["name"], caps))
|
|
61
|
+
return out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if endpointkit is not None:
|
|
65
|
+
|
|
66
|
+
class Servers(endpointkit.Provider):
|
|
67
|
+
"""The servers Huey's settings give, as endpoints of ``assistant``."""
|
|
68
|
+
|
|
69
|
+
def __init__(self, settings):
|
|
70
|
+
endpointkit.Provider.__init__(self, "assistant", NAME)
|
|
71
|
+
self._settings = settings
|
|
72
|
+
self._dirty = False
|
|
73
|
+
|
|
74
|
+
def update(self, settings):
|
|
75
|
+
"""Take newly loaded *settings*; the list changes at the next poll."""
|
|
76
|
+
if entries(settings) != entries(self._settings):
|
|
77
|
+
self._dirty = True
|
|
78
|
+
self._settings = settings
|
|
79
|
+
|
|
80
|
+
def scan(self):
|
|
81
|
+
return [self.endpoint(i, label, caps=caps) for i, label, caps in entries(self._settings)]
|
|
82
|
+
|
|
83
|
+
def poll(self):
|
|
84
|
+
if self._dirty:
|
|
85
|
+
self._dirty = False
|
|
86
|
+
return self.scan()
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def use(settings, registry=None):
|
|
91
|
+
"""*settings* with the chosen assistant's over them.
|
|
92
|
+
|
|
93
|
+
Registers Huey's servers with *registry* (the device's when None) the
|
|
94
|
+
first time, and gives it the latest settings after. When the device has
|
|
95
|
+
chosen an assistant that is found, its caps (an address, models, a key
|
|
96
|
+
file) replace those settings; otherwise *settings* come back as they are.
|
|
97
|
+
"""
|
|
98
|
+
if endpointkit is None:
|
|
99
|
+
return settings
|
|
100
|
+
reg = registry if registry is not None else endpointkit.registry
|
|
101
|
+
mine = None
|
|
102
|
+
for p in reg.providers("assistant"):
|
|
103
|
+
if p.name == NAME:
|
|
104
|
+
mine = p
|
|
105
|
+
if mine is None:
|
|
106
|
+
if "assistant" not in endpointkit.KINDS:
|
|
107
|
+
# An endpointkit from before the kind was built in.
|
|
108
|
+
endpointkit.add_kind("assistant", endpointkit.ONE)
|
|
109
|
+
mine = Servers(settings)
|
|
110
|
+
reg.register(mine)
|
|
111
|
+
else:
|
|
112
|
+
mine.update(settings)
|
|
113
|
+
reg.poll()
|
|
114
|
+
chosen = reg.selected("assistant")
|
|
115
|
+
if not chosen:
|
|
116
|
+
return settings
|
|
117
|
+
out = dict(settings)
|
|
118
|
+
for k in CAPS:
|
|
119
|
+
if k in chosen[0].caps:
|
|
120
|
+
out[k] = chosen[0].caps[k]
|
|
121
|
+
return out
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"base_url": "https://api.deepinfra.com/v1/openai",
|
|
3
|
+
"key_file": "/deepinfra.key",
|
|
4
|
+
"stt_model": "openai/whisper-large-v3-turbo",
|
|
5
|
+
"chat_model": "mistralai/Mistral-Small-3.2-24B-Instruct-2506",
|
|
6
|
+
"tts_model": "inworld-ai/realtime-tts-1.5-mini",
|
|
7
|
+
"voice": "Dennis"
|
|
8
|
+
}
|