danielritchie commited on
Commit
bdae7d0
·
verified ·
1 Parent(s): fa5a939

Sync from GitHub via hub-sync

Browse files
pyproject.toml CHANGED
@@ -16,24 +16,20 @@ dependencies = [
16
  "gradio==5.50.1.dev1",
17
  "huggingface-hub==1.3.0",
18
  "opencv-python>=4.12.0.88",
19
-
20
  #Environment variables
21
  "python-dotenv",
22
-
23
  #OpenAI
24
  "openai>=2.1",
25
-
26
  #Reachy mini
27
  "reachy_mini_dances_library",
28
  "reachy_mini_toolbox",
29
  "reachy-mini>=1.3.1",
30
  "eclipse-zenoh~=1.7.0",
31
  "gradio_client>=1.13.3",
32
-
33
  #Emotional Engine & Display
34
  "anima-engine",
35
  "anima-reachy-conversation",
36
-
37
  ]
38
 
39
  [project.optional-dependencies]
 
16
  "gradio==5.50.1.dev1",
17
  "huggingface-hub==1.3.0",
18
  "opencv-python>=4.12.0.88",
 
19
  #Environment variables
20
  "python-dotenv",
 
21
  #OpenAI
22
  "openai>=2.1",
 
23
  #Reachy mini
24
  "reachy_mini_dances_library",
25
  "reachy_mini_toolbox",
26
  "reachy-mini>=1.3.1",
27
  "eclipse-zenoh~=1.7.0",
28
  "gradio_client>=1.13.3",
 
29
  #Emotional Engine & Display
30
  "anima-engine",
31
  "anima-reachy-conversation",
32
+ "reachy-eyes>=0.1.0",
33
  ]
34
 
35
  [project.optional-dependencies]
src/anima_conversation_app/config.py CHANGED
@@ -169,8 +169,11 @@ class Config:
169
  str(Path(__file__).resolve().parents[2] / "data" / "NRC-VAD-Lexicon-v2.1" / "NRC-VAD-Lexicon-v2.1.txt"),
170
  )
171
 
 
172
  ANIMA_TRANSITION_SIGMA: float = float(os.getenv("ANIMA_TRANSITION_SIGMA", "0.17"))
 
173
  ANIMA_VADCC_EXPONENT: float = float(os.getenv("ANIMA_VADCC_EXPONENT", "0.84"))
 
174
 
175
  # Behavior baseline for breathing, speech sway, and idle antenna motion
176
  ANTENNA_BASE_AMPLITUDE: float = float(os.getenv("ANTENNA_BASE_AMPLITUDE", "12.0"))
 
169
  str(Path(__file__).resolve().parents[2] / "data" / "NRC-VAD-Lexicon-v2.1" / "NRC-VAD-Lexicon-v2.1.txt"),
170
  )
171
 
172
+
173
  ANIMA_TRANSITION_SIGMA: float = float(os.getenv("ANIMA_TRANSITION_SIGMA", "0.17"))
174
+ # Separate amplifier for independent tuning of eyes vs. body, lower is more intense
175
  ANIMA_VADCC_EXPONENT: float = float(os.getenv("ANIMA_VADCC_EXPONENT", "0.84"))
176
+ ANIMA_EYE_VADCC_EXPONENT: float = float(os.getenv("ANIMA_EYE_VADCC_EXPONENT", "0.4"))
177
 
178
  # Behavior baseline for breathing, speech sway, and idle antenna motion
179
  ANTENNA_BASE_AMPLITUDE: float = float(os.getenv("ANTENNA_BASE_AMPLITUDE", "12.0"))
src/anima_conversation_app/openai_realtime.py CHANGED
@@ -18,6 +18,7 @@ from websockets.exceptions import ConnectionClosedError
18
 
19
  from anima import Anima, Config as AnimaConfig
20
  from anima_reachy_conversation import MovementAdapter
 
21
 
22
  from anima_conversation_app.config import config
23
  from anima_conversation_app.prompts import get_session_voice, get_session_instructions
@@ -76,6 +77,7 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
76
  # Anima emotional engine integration
77
  self.anima: Optional[Anima] = None
78
  self.movement_adapter: Optional[MovementAdapter] = None
 
79
  self._anima_writer = anima_writer
80
 
81
  # Internal lifecycle flags
@@ -207,6 +209,22 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
207
 
208
  # Wire adapter into MovementManager
209
  self.deps.movement_manager.set_movement_adapter(self.movement_adapter)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
  logger.info("✓ Anima emotional engine initialized")
212
  except Exception as e:
@@ -774,4 +792,4 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
774
  logger.info("Created %s and stored OPENAI_API_KEY for future runs.", env_path)
775
  except Exception as e:
776
  # Never crash the app for QoL persistence; just log.
777
- logger.warning("Could not persist OPENAI_API_KEY to .env: %s", e)
 
18
 
19
  from anima import Anima, Config as AnimaConfig
20
  from anima_reachy_conversation import MovementAdapter
21
+ from anima_conversation_app.reachy_eyes_adapter import ReachyEyesAdapter
22
 
23
  from anima_conversation_app.config import config
24
  from anima_conversation_app.prompts import get_session_voice, get_session_instructions
 
77
  # Anima emotional engine integration
78
  self.anima: Optional[Anima] = None
79
  self.movement_adapter: Optional[MovementAdapter] = None
80
+ self.reachy_eyes_adapter: Optional[ReachyEyesAdapter] = None
81
  self._anima_writer = anima_writer
82
 
83
  # Internal lifecycle flags
 
209
 
210
  # Wire adapter into MovementManager
211
  self.deps.movement_manager.set_movement_adapter(self.movement_adapter)
212
+
213
+ # Wire eye color adapter
214
+ try:
215
+ from reachy_eyes import ReachyEyes
216
+ from reachy_eyes.device import EyesDevice
217
+ eyes = ReachyEyes(EyesDevice.discover())
218
+ logger.info("[EYES] Hardware initialized")
219
+ except Exception as e:
220
+ logger.warning("[EYES] Eye hardware not found, running without eyes: %s", e)
221
+ eyes = None
222
+ self.reachy_eyes_adapter = ReachyEyesAdapter(
223
+ eyes,
224
+ vadcc_exponent=config.ANIMA_EYE_VADCC_EXPONENT,
225
+ )
226
+ self.anima.subscribe(self.reachy_eyes_adapter.update)
227
+
228
 
229
  logger.info("✓ Anima emotional engine initialized")
230
  except Exception as e:
 
792
  logger.info("Created %s and stored OPENAI_API_KEY for future runs.", env_path)
793
  except Exception as e:
794
  # Never crash the app for QoL persistence; just log.
795
+ logger.warning("Could not persist OPENAI_API_KEY to .env: %s", e)
src/anima_conversation_app/reachy_eyes_adapter.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Eye color adapter for Anima → ReachyEyes.
2
+
3
+ Bridges the Anima emotional engine to the reachy-eyes hardware component
4
+ by forwarding VADCC tuples directly as VIBE commands. The eye firmware
5
+ interprets VADCC natively, so no manifold mapping is needed here.
6
+
7
+ Usage:
8
+ eyes = robot.component["reachy-eyes"]
9
+ adapter = ReachyEyesAdapter(eyes)
10
+ anima.subscribe(adapter.update)
11
+ """
12
+
13
+ import logging
14
+ import numpy as np
15
+ import time
16
+ from typing import Optional, Tuple
17
+
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ class ReachyEyesAdapter:
23
+ """Forward Anima VADCC to ReachyEyes as VIBE commands.
24
+
25
+ The eye firmware accepts VADCC directly via the VIBE protocol command,
26
+ so this adapter is intentionally thin — it owns only rate-limiting and
27
+ graceful degradation when the eye component is absent.
28
+ """
29
+
30
+ # Minimum seconds between VIBE commands sent to the device.
31
+ # The eye firmware smooths transitions itself (COLOR_TAU), so sending
32
+ # faster than ~10 Hz would be wasteful without improving perceived quality.
33
+ _MIN_SEND_INTERVAL: float = 0.1
34
+
35
+ def __init__(
36
+ self,
37
+ eyes, # ReachyEyes instance, or None when hardware is unavailable
38
+ min_send_interval: float = _MIN_SEND_INTERVAL,
39
+ vadcc_exponent: float = 0.84,
40
+ ) -> None:
41
+ """Initialise the adapter.
42
+
43
+ Args:
44
+ eyes: A ``ReachyEyes`` instance obtained from
45
+ ``robot.component["reachy-eyes"]``. If ``None``, all
46
+ ``update()`` calls are silently ignored so the rest of the
47
+ app continues without eye hardware.
48
+ min_send_interval: Minimum seconds between VIBE commands.
49
+ Defaults to 0.1 s (10 Hz).
50
+ """
51
+ self._eyes = eyes
52
+ self._min_send_interval = min_send_interval
53
+ self._vadcc_exponent = vadcc_exponent
54
+ self._last_send_time: float = 0.0
55
+ self._last_vadcc: Optional[Tuple[float, float, float, float, float]] = None
56
+ self._last_log_time: float = 0.0
57
+
58
+ if eyes is None:
59
+ logger.warning("[EYE] No eye hardware available — ReachyEyesAdapter running in no-op mode")
60
+ else:
61
+ logger.info("[EYE] ReachyEyesAdapter initialised")
62
+
63
+ # ------------------------------------------------------------------
64
+ # Anima subscriber interface
65
+ # ------------------------------------------------------------------
66
+
67
+ def _amplify_vadcc(
68
+ self, vadcc: Tuple[float, float, float, float, float]
69
+ ) -> Tuple[float, float, float, float, float]:
70
+ centered = np.array(vadcc) - 0.5
71
+ amplified = np.sign(centered) * np.power(np.abs(centered), self._vadcc_exponent)
72
+ return tuple(0.5 + amplified)
73
+
74
+ def update(self, vadcc: Tuple[float, float, float, float, float]) -> None:
75
+ """Receive a VADCC tuple from Anima and forward it to the eyes.
76
+
77
+ This method is called by Anima on every emotional state update and
78
+ must return quickly — no blocking I/O, no heavy computation.
79
+
80
+ Args:
81
+ vadcc: (valence, arousal, dominance, complexity, coherence),
82
+ each in [0.0, 1.0].
83
+ """
84
+ if self._eyes is None:
85
+ return
86
+
87
+ now = time.monotonic()
88
+ if now - self._last_send_time < self._min_send_interval:
89
+ return
90
+
91
+ val, aro, dom, cplx, coh = self._amplify_vadcc(vadcc)
92
+
93
+ try:
94
+ self._eyes._device.send_command(
95
+ f"VIBE {val:.4f} {aro:.4f} {dom:.4f} {cplx:.4f} {coh:.4f}"
96
+ )
97
+ self._last_send_time = now
98
+ except Exception as e:
99
+ # Never crash the calling thread (Anima's subscriber loop).
100
+ logger.debug("[EYE] Failed to send VIBE command: %s", e)
101
+ return
102
+
103
+ # Sparse debug logging — at most once per second, only on change.
104
+ rounded = tuple(round(v, 3) for v in vadcc)
105
+ if rounded != self._last_vadcc and (now - self._last_log_time) >= 1.0:
106
+ logger.debug(
107
+ "[EYE] VIBE V:%.3f A:%.3f D:%.3f Cx:%.3f Ch:%.3f",
108
+ val, aro, dom, cplx, coh,
109
+ )
110
+ self._last_vadcc = rounded
111
+ self._last_log_time = now
uv.lock CHANGED
@@ -180,6 +180,7 @@ dependencies = [
180
  { name = "openai" },
181
  { name = "opencv-python" },
182
  { name = "python-dotenv" },
 
183
  { name = "reachy-mini" },
184
  { name = "reachy-mini-dances-library" },
185
  { name = "reachy-mini-toolbox" },
@@ -241,6 +242,7 @@ requires-dist = [
241
  { name = "opencv-python", specifier = ">=4.12.0.88" },
242
  { name = "pygobject", marker = "extra == 'reachy-mini-wireless'", specifier = ">=3.42.2,<=3.46.0" },
243
  { name = "python-dotenv" },
 
244
  { name = "reachy-mini", specifier = ">=1.3.1" },
245
  { name = "reachy-mini-dances-library" },
246
  { name = "reachy-mini-toolbox" },
@@ -3415,6 +3417,18 @@ wheels = [
3415
  { url = "https://files.pythonhosted.org/packages/3c/26/1062c7ec1b053db9e499b4d2d5bc231743201b74051c973dadeac80a8f43/questionary-2.1.1-py3-none-any.whl", hash = "sha256:a51af13f345f1cdea62347589fbb6df3b290306ab8930713bfae4d475a7d4a59", size = 36753, upload-time = "2025-08-28T19:00:19.56Z" },
3416
  ]
3417
 
 
 
 
 
 
 
 
 
 
 
 
 
3418
  [[package]]
3419
  name = "reachy-mini"
3420
  version = "1.3.1"
 
180
  { name = "openai" },
181
  { name = "opencv-python" },
182
  { name = "python-dotenv" },
183
+ { name = "reachy-eyes" },
184
  { name = "reachy-mini" },
185
  { name = "reachy-mini-dances-library" },
186
  { name = "reachy-mini-toolbox" },
 
242
  { name = "opencv-python", specifier = ">=4.12.0.88" },
243
  { name = "pygobject", marker = "extra == 'reachy-mini-wireless'", specifier = ">=3.42.2,<=3.46.0" },
244
  { name = "python-dotenv" },
245
+ { name = "reachy-eyes", specifier = ">=0.1.0" },
246
  { name = "reachy-mini", specifier = ">=1.3.1" },
247
  { name = "reachy-mini-dances-library" },
248
  { name = "reachy-mini-toolbox" },
 
3417
  { url = "https://files.pythonhosted.org/packages/3c/26/1062c7ec1b053db9e499b4d2d5bc231743201b74051c973dadeac80a8f43/questionary-2.1.1-py3-none-any.whl", hash = "sha256:a51af13f345f1cdea62347589fbb6df3b290306ab8930713bfae4d475a7d4a59", size = 36753, upload-time = "2025-08-28T19:00:19.56Z" },
3418
  ]
3419
 
3420
+ [[package]]
3421
+ name = "reachy-eyes"
3422
+ version = "0.1.0"
3423
+ source = { registry = "https://pypi.org/simple" }
3424
+ dependencies = [
3425
+ { name = "pyserial" },
3426
+ ]
3427
+ sdist = { url = "https://files.pythonhosted.org/packages/f0/ce/0689d165a030cfdbb121e1f33fadb28243f71fe83920ae8cdb0490c5be7b/reachy_eyes-0.1.0.tar.gz", hash = "sha256:67e447b2bd2686190bf6c89640c242d3223de245f5d92756b1e6e67d478049ef", size = 12160, upload-time = "2026-03-04T23:30:21.251Z" }
3428
+ wheels = [
3429
+ { url = "https://files.pythonhosted.org/packages/26/32/bae5af0eb68a32abb9117b41f419fd33211cfa71e5c62026d1ea2886fdce/reachy_eyes-0.1.0-py3-none-any.whl", hash = "sha256:74c766126d47183881225a93d24417a955942dc05a3f94337bacc30b9525c1f1", size = 10501, upload-time = "2026-03-04T23:30:19.952Z" },
3430
+ ]
3431
+
3432
  [[package]]
3433
  name = "reachy-mini"
3434
  version = "1.3.1"