gamst-sdk 0.4.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.
- gamst/__init__.py +70 -0
- gamst/__main__.py +3 -0
- gamst/audiovisual.py +300 -0
- gamst/cadence.py +52 -0
- gamst/calibrate.py +54 -0
- gamst/call_budget.py +220 -0
- gamst/call_controller.py +483 -0
- gamst/call_policy.py +133 -0
- gamst/camera_similarity.py +158 -0
- gamst/capabilities.py +206 -0
- gamst/capture.py +381 -0
- gamst/cli.py +98 -0
- gamst/companion.py +199 -0
- gamst/context.py +77 -0
- gamst/context_memory.py +303 -0
- gamst/contradictions.py +257 -0
- gamst/crew_bridge.py +70 -0
- gamst/dashboard.html +144 -0
- gamst/dashboard.py +384 -0
- gamst/demos/__init__.py +1 -0
- gamst/demos/coin_halo.py +348 -0
- gamst/emotion2vec_export.py +293 -0
- gamst/engine.py +1393 -0
- gamst/evaluation_publication.py +14 -0
- gamst/evaluation_snapshot.py +221 -0
- gamst/extensions.py +95 -0
- gamst/feedback.py +217 -0
- gamst/fill_conflict.py +299 -0
- gamst/fill_conflict_rule.py +99 -0
- gamst/fill_evaluation.py +31 -0
- gamst/frame_sentinel.py +336 -0
- gamst/i18n.js +17 -0
- gamst/integrations.py +281 -0
- gamst/mask_tracking.py +81 -0
- gamst/mcp.py +486 -0
- gamst/mcp_live.py +52 -0
- gamst/media.py +221 -0
- gamst/memory.py +151 -0
- gamst/native_entry.py +95 -0
- gamst/native_operation.py +47 -0
- gamst/object_appearance.py +99 -0
- gamst/observability.js +75 -0
- gamst/observation_pages.py +61 -0
- gamst/openai_responses.py +259 -0
- gamst/openai_responses_codec.py +143 -0
- gamst/openeb_capture_worker.py +53 -0
- gamst/openeb_process.py +235 -0
- gamst/orbslam_process.py +151 -0
- gamst/pg_artifact.py +187 -0
- gamst/pg_canonical.py +340 -0
- gamst/pg_canonical_process.py +145 -0
- gamst/pg_canonical_worker.py +57 -0
- gamst/pg_generation.py +173 -0
- gamst/pg_graph.py +406 -0
- gamst/pg_physical_process.py +187 -0
- gamst/pg_physical_worker.py +53 -0
- gamst/pg_sources.py +19 -0
- gamst/plugins.py +369 -0
- gamst/process_provider.py +353 -0
- gamst/provider_profiles.py +243 -0
- gamst/provider_wire.py +98 -0
- gamst/provider_worker.py +261 -0
- gamst/providers/__init__.py +5 -0
- gamst/providers/anchor_events.py +53 -0
- gamst/providers/angular_motion.py +67 -0
- gamst/providers/audio_context.py +160 -0
- gamst/providers/beamforming.py +101 -0
- gamst/providers/body_context.py +128 -0
- gamst/providers/bsec2.py +210 -0
- gamst/providers/ced_events.py +290 -0
- gamst/providers/compensated_trajectories.py +205 -0
- gamst/providers/csi.py +200 -0
- gamst/providers/depth.py +126 -0
- gamst/providers/detection.py +217 -0
- gamst/providers/detection_trajectories.py +138 -0
- gamst/providers/diarization.py +268 -0
- gamst/providers/direction.py +189 -0
- gamst/providers/duplex.py +182 -0
- gamst/providers/efficientphys_context.py +254 -0
- gamst/providers/efficientphys_native.py +119 -0
- gamst/providers/efficienttam_context.py +166 -0
- gamst/providers/efficienttam_native.py +126 -0
- gamst/providers/efficienttam_sources.py +34 -0
- gamst/providers/efficienttam_stream.py +186 -0
- gamst/providers/endpoint_asr.py +146 -0
- gamst/providers/environment_audio.py +164 -0
- gamst/providers/face_context.py +154 -0
- gamst/providers/factorizephys_context.py +166 -0
- gamst/providers/fill.py +128 -0
- gamst/providers/flight.py +234 -0
- gamst/providers/food.py +158 -0
- gamst/providers/gaze.py +153 -0
- gamst/providers/gemini.py +228 -0
- gamst/providers/gesture_context.py +78 -0
- gamst/providers/ground_plane.py +110 -0
- gamst/providers/hand_context.py +151 -0
- gamst/providers/head_orientation.py +188 -0
- gamst/providers/huggingface.py +101 -0
- gamst/providers/image_events.py +107 -0
- gamst/providers/imu.py +97 -0
- gamst/providers/intern_decision.py +401 -0
- gamst/providers/kinematics.py +150 -0
- gamst/providers/landmarker_video.py +163 -0
- gamst/providers/moonshine_asr.py +295 -0
- gamst/providers/motion.py +119 -0
- gamst/providers/multimodal_decision.py +207 -0
- gamst/providers/object_events.py +148 -0
- gamst/providers/object_rotation_bank.py +41 -0
- gamst/providers/object_spin.py +285 -0
- gamst/providers/ocr.py +172 -0
- gamst/providers/ocsort.py +444 -0
- gamst/providers/ollama.py +78 -0
- gamst/providers/openeb.py +164 -0
- gamst/providers/openeb_capture.py +121 -0
- gamst/providers/orbslam_context.py +124 -0
- gamst/providers/orbslam_native.py +168 -0
- gamst/providers/physical_state.py +802 -0
- gamst/providers/piv.py +148 -0
- gamst/providers/pose.py +149 -0
- gamst/providers/prosody.py +143 -0
- gamst/providers/prosody_features.py +63 -0
- gamst/providers/qwen_asr.py +175 -0
- gamst/providers/radar.py +270 -0
- gamst/providers/region_appearance.py +149 -0
- gamst/providers/repetition.py +154 -0
- gamst/providers/rhythm.py +186 -0
- gamst/providers/risk_field.py +171 -0
- gamst/providers/sam3.py +255 -0
- gamst/providers/sam31_video.py +374 -0
- gamst/providers/sam_audio_context.py +164 -0
- gamst/providers/sam_audio_native.py +607 -0
- gamst/providers/shape_tracks.py +223 -0
- gamst/providers/smolvlm_context.py +132 -0
- gamst/providers/smolvlm_native.py +174 -0
- gamst/providers/sparsh_context.py +243 -0
- gamst/providers/sparsh_native.py +223 -0
- gamst/providers/sparsh_sources.py +216 -0
- gamst/providers/srp.py +112 -0
- gamst/providers/stereo_context.py +217 -0
- gamst/providers/stereo_metric.py +148 -0
- gamst/providers/streaming_semantic.py +173 -0
- gamst/providers/tactile.py +261 -0
- gamst/providers/tactile_capture.py +202 -0
- gamst/providers/talknet.py +268 -0
- gamst/providers/ten_vad.py +248 -0
- gamst/providers/tennis_image.py +186 -0
- gamst/providers/thermal.py +105 -0
- gamst/providers/timeseries.py +103 -0
- gamst/providers/trajectories.py +143 -0
- gamst/providers/vad.py +142 -0
- gamst/providers/video_depth.py +296 -0
- gamst/providers/visual_microphone.py +164 -0
- gamst/providers/visual_microphone_context.py +192 -0
- gamst/providers/visual_retrieval.py +130 -0
- gamst/providers/vocal_expression.py +161 -0
- gamst/providers/yoloe.py +205 -0
- gamst/providers/yoloe_native.py +236 -0
- gamst/qwen_artifact.py +69 -0
- gamst/realtime.py +254 -0
- gamst/reasoning.py +332 -0
- gamst/recording_scope.py +134 -0
- gamst/recording_settlement.py +390 -0
- gamst/responses_evidence.py +142 -0
- gamst/responses_evidence_reader.py +178 -0
- gamst/sam_audio_artifact.py +272 -0
- gamst/sam_audio_source_hashes.py +80 -0
- gamst/sam_audio_sources.py +64 -0
- gamst/sam_audio_visual.py +104 -0
- gamst/sam_audio_windows.py +146 -0
- gamst/sam_visual_history.py +91 -0
- gamst/sam_visual_packet.py +280 -0
- gamst/sam_visual_replay.py +96 -0
- gamst/sam_visual_window.py +69 -0
- gamst/schema.py +67 -0
- gamst/semantic_fusion.py +61 -0
- gamst/semantic_state.py +96 -0
- gamst/separation_media.py +351 -0
- gamst/separation_metadata.py +166 -0
- gamst/server.py +226 -0
- gamst/settings.py +34 -0
- gamst/smolvlm_call.py +223 -0
- gamst/sparsh_replay.py +26 -0
- gamst/speaking_rate.py +85 -0
- gamst/star.py +62 -0
- gamst/stereo_packet.py +128 -0
- gamst/stereo_replay.py +124 -0
- gamst/storage.py +251 -0
- gamst/streams.py +804 -0
- gamst/tactile_replay.py +20 -0
- gamst/temporal.py +524 -0
- gamst/temporal_context.py +153 -0
- gamst/text_context_call.py +204 -0
- gamst/tracking.py +179 -0
- gamst/transcripts.py +166 -0
- gamst/usecases/__init__.py +5 -0
- gamst/usecases/coin_wow.py +175 -0
- gamst/visual_context_call.py +73 -0
- gamst/visualization.py +26 -0
- gamst/vlm_metrics.py +90 -0
- gamst/voice_backend.py +46 -0
- gamst/watch.py +381 -0
- gamst/ws_auth.py +65 -0
- gamst_sdk-0.4.0.dist-info/METADATA +923 -0
- gamst_sdk-0.4.0.dist-info/RECORD +208 -0
- gamst_sdk-0.4.0.dist-info/WHEEL +5 -0
- gamst_sdk-0.4.0.dist-info/entry_points.txt +6 -0
- gamst_sdk-0.4.0.dist-info/licenses/LICENSE +202 -0
- gamst_sdk-0.4.0.dist-info/top_level.txt +1 -0
gamst/__init__.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Gamst: local, evidence-grounded human interaction intelligence."""
|
|
2
|
+
from .engine import Gamst, PerceptionPlugin
|
|
3
|
+
from .schema import SCHEMA_VERSION, validate_output
|
|
4
|
+
from .feedback import CalibrationArtifact, LabeledOutcome, fit_calibration
|
|
5
|
+
from .capabilities import CapabilitySpec, CapabilityRegistry, OutputField, SensorMetadata
|
|
6
|
+
from .streams import SensorStreams
|
|
7
|
+
from .process_provider import ProcessProvider
|
|
8
|
+
|
|
9
|
+
Observer = Gamst
|
|
10
|
+
__version__ = "0.4.0"
|
|
11
|
+
__all__ = ["Gamst", "Observer", "PerceptionPlugin", "SCHEMA_VERSION", "validate_output", "CalibrationArtifact", "LabeledOutcome", "fit_calibration"]
|
|
12
|
+
__all__ += ['CapabilitySpec', 'CapabilityRegistry', 'OutputField', 'SensorMetadata']
|
|
13
|
+
__all__ += ['SensorStreams']
|
|
14
|
+
__all__ += ['ProcessProvider']
|
|
15
|
+
|
|
16
|
+
from .providers.multimodal_decision import MultimodalDecisionProvider
|
|
17
|
+
__all__ += ['MultimodalDecisionProvider']
|
|
18
|
+
|
|
19
|
+
from .transcripts import transcript_capability
|
|
20
|
+
__all__ += ['transcript_capability']
|
|
21
|
+
|
|
22
|
+
from .contradictions import (contradiction_candidate, detect_contradictions,
|
|
23
|
+
detect_contradiction_candidates)
|
|
24
|
+
__all__ += ['contradiction_candidate', 'detect_contradictions',
|
|
25
|
+
'detect_contradiction_candidates']
|
|
26
|
+
|
|
27
|
+
from .object_appearance import ObjectAppearancePipeline
|
|
28
|
+
__all__ += ['ObjectAppearancePipeline']
|
|
29
|
+
|
|
30
|
+
from .mask_tracking import MaskTrackingPipeline
|
|
31
|
+
__all__ += ['MaskTrackingPipeline']
|
|
32
|
+
|
|
33
|
+
from .audiovisual import TalkNetWindows, decode_talknet_window, talknet_stream_frame
|
|
34
|
+
__all__ += ['TalkNetWindows', 'decode_talknet_window', 'talknet_stream_frame']
|
|
35
|
+
|
|
36
|
+
from .openeb_process import OpenEBProcess
|
|
37
|
+
__all__ += ['OpenEBProcess']
|
|
38
|
+
|
|
39
|
+
from .smolvlm_call import SmolVLMCalls, smolvlm_frame_sha256
|
|
40
|
+
__all__ += ['SmolVLMCalls', 'smolvlm_frame_sha256']
|
|
41
|
+
|
|
42
|
+
from .frame_sentinel import FreshFrameSentinel
|
|
43
|
+
__all__ += ['FreshFrameSentinel']
|
|
44
|
+
|
|
45
|
+
from .text_context_call import TextContextCalls
|
|
46
|
+
__all__ += ['TextContextCalls']
|
|
47
|
+
|
|
48
|
+
from .visual_context_call import VisualContextCalls
|
|
49
|
+
__all__ += ['VisualContextCalls']
|
|
50
|
+
|
|
51
|
+
from .orbslam_process import ORBSLAMProcess
|
|
52
|
+
__all__ += ['ORBSLAMProcess']
|
|
53
|
+
|
|
54
|
+
from .fill_conflict import FillConflictRuntime
|
|
55
|
+
__all__ += ['FillConflictRuntime']
|
|
56
|
+
|
|
57
|
+
from .evaluation_snapshot import (SourceContextView, EvaluationSnapshotPublisher,
|
|
58
|
+
evaluation_snapshot_implementation_sha256)
|
|
59
|
+
__all__ += ['SourceContextView', 'EvaluationSnapshotPublisher', 'evaluation_snapshot_implementation_sha256']
|
|
60
|
+
|
|
61
|
+
from .openai_responses import OpenAIResponsesClient
|
|
62
|
+
from .responses_evidence import ResponsesEvidenceSession
|
|
63
|
+
from .responses_evidence_reader import read_responses_evidence
|
|
64
|
+
__all__ += ['OpenAIResponsesClient', 'ResponsesEvidenceSession', 'read_responses_evidence']
|
|
65
|
+
|
|
66
|
+
from .temporal_context import TemporalContextEngine
|
|
67
|
+
from .context_memory import (CheckpointStore, ContextMemory, ContextMemoryEngine,
|
|
68
|
+
MemoryContext, project_record, sync_records)
|
|
69
|
+
__all__ += ['TemporalContextEngine', 'CheckpointStore', 'ContextMemory', 'ContextMemoryEngine',
|
|
70
|
+
'MemoryContext', 'project_record', 'sync_records']
|
gamst/__main__.py
ADDED
gamst/audiovisual.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""Bounded same-clock face/PCM windows for the TalkNet worker boundary.
|
|
2
|
+
|
|
3
|
+
This module aligns media; it does not infer speaking, identity or clock sync.
|
|
4
|
+
"""
|
|
5
|
+
from dataclasses import asdict, replace
|
|
6
|
+
import json
|
|
7
|
+
import struct
|
|
8
|
+
import threading
|
|
9
|
+
import uuid
|
|
10
|
+
|
|
11
|
+
from .capabilities import SensorMetadata, bounded_json, identifier
|
|
12
|
+
from .plugins import InputFrame
|
|
13
|
+
|
|
14
|
+
_MAGIC = b'GTAV001\n'
|
|
15
|
+
_MAX_HEADER = 8192
|
|
16
|
+
_MAX_PACKET = 2_100_000
|
|
17
|
+
_KEYS = {'version', 'clock_id', 'session_id', 'track_id', 'subject_id', 'start_ms',
|
|
18
|
+
'video_end_ms', 'audio_end_ms', 'frames', 'audio_sensor', 'video_sensor',
|
|
19
|
+
'audio_sequence', 'video_sequence', 'synchronization_verified', 'identity_verified'}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _sensor(sensor):
|
|
23
|
+
value = asdict(sensor)
|
|
24
|
+
value.pop('sequence')
|
|
25
|
+
value.pop('capture_sequence')
|
|
26
|
+
value['channels'] = list(value['channels'])
|
|
27
|
+
value['sequence_kind'] = 'capture' if sensor.capture_sequence is not None else 'sensor'
|
|
28
|
+
return value
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _metadata(value):
|
|
32
|
+
value = bounded_json(value, max_bytes=_MAX_HEADER)
|
|
33
|
+
if type(value) is not dict or set(value) != _KEYS or type(value['version']) is not int or value['version'] != 1:
|
|
34
|
+
raise ValueError('invalid audiovisual packet metadata')
|
|
35
|
+
for name in ('clock_id', 'session_id', 'track_id', 'subject_id'):
|
|
36
|
+
identifier(value[name], name)
|
|
37
|
+
n, start, end, audio_end = (value[k] for k in ('frames', 'start_ms', 'video_end_ms', 'audio_end_ms'))
|
|
38
|
+
if (type(n) is not int or n not in (25, 50, 75, 100, 125, 150) or
|
|
39
|
+
any(type(x) is not int or not 0 <= x <= 2**53-1 for x in (start, end, audio_end)) or
|
|
40
|
+
end != start+n*40 or audio_end != end+15):
|
|
41
|
+
raise ValueError('invalid audiovisual capture interval')
|
|
42
|
+
if value['synchronization_verified'] is not False or value['identity_verified'] is not False:
|
|
43
|
+
raise ValueError('alignment declarations do not verify sync or identity')
|
|
44
|
+
for lane in ('audio', 'video'):
|
|
45
|
+
source = value[lane+'_sensor']
|
|
46
|
+
if type(source) is not dict or source.get('sequence_kind') not in ('capture', 'sensor'):
|
|
47
|
+
raise ValueError('invalid audiovisual source provenance')
|
|
48
|
+
source = dict(source)
|
|
49
|
+
source.pop('sequence_kind')
|
|
50
|
+
if type(source.get('channels')) is not list:
|
|
51
|
+
raise ValueError('invalid audiovisual channels')
|
|
52
|
+
source['channels'] = tuple(source['channels'])
|
|
53
|
+
try:
|
|
54
|
+
sensor = SensorMetadata(sequence=0, **source)
|
|
55
|
+
except (TypeError, ValueError) as exc:
|
|
56
|
+
raise ValueError('invalid audiovisual source provenance') from exc
|
|
57
|
+
if lane == 'audio' and len(sensor.channels) != 1:
|
|
58
|
+
raise ValueError('mono audio provenance required')
|
|
59
|
+
pair = value[lane+'_sequence']
|
|
60
|
+
if (type(pair) is not list or len(pair) != 2 or
|
|
61
|
+
any(type(v) is not int or not 0 <= v <= 2**63-1 for v in pair) or pair[1] < pair[0]):
|
|
62
|
+
raise ValueError('invalid audiovisual sequence range')
|
|
63
|
+
if lane == 'video' and pair[1]-pair[0] != n-1:
|
|
64
|
+
raise ValueError('video sequence range must cover every face frame')
|
|
65
|
+
return value
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _encode(metadata, pcm, faces):
|
|
69
|
+
header = json.dumps(_metadata(metadata), separators=(',', ':'), ensure_ascii=True).encode()
|
|
70
|
+
packet = _MAGIC+struct.pack('!I', len(header))+header+pcm+faces
|
|
71
|
+
if len(packet) > _MAX_PACKET:
|
|
72
|
+
raise ValueError('audiovisual packet exceeds bound')
|
|
73
|
+
return packet
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def decode_talknet_window(packet):
|
|
77
|
+
"""Validate a local worker packet; return metadata and owned PCM/face arrays."""
|
|
78
|
+
if type(packet) is not bytes or not 12 <= len(packet) <= _MAX_PACKET or packet[:8] != _MAGIC:
|
|
79
|
+
raise ValueError('invalid audiovisual packet')
|
|
80
|
+
size = struct.unpack('!I', packet[8:12])[0]
|
|
81
|
+
if not 1 <= size <= _MAX_HEADER or len(packet) < 12+size:
|
|
82
|
+
raise ValueError('invalid audiovisual header length')
|
|
83
|
+
def pairs(items):
|
|
84
|
+
result = {}
|
|
85
|
+
for key, value in items:
|
|
86
|
+
if key in result:
|
|
87
|
+
raise ValueError('duplicate audiovisual metadata key')
|
|
88
|
+
result[key] = value
|
|
89
|
+
return result
|
|
90
|
+
try:
|
|
91
|
+
metadata = _metadata(json.loads(packet[12:12+size], object_pairs_hook=pairs))
|
|
92
|
+
except (UnicodeError, RecursionError, json.JSONDecodeError) as exc:
|
|
93
|
+
raise ValueError('invalid audiovisual JSON') from exc
|
|
94
|
+
n = metadata['frames']
|
|
95
|
+
samples = n*640+240
|
|
96
|
+
offset = 12+size
|
|
97
|
+
if len(packet) != offset+samples*2+n*112*112:
|
|
98
|
+
raise ValueError('audiovisual payload length mismatch')
|
|
99
|
+
import numpy as np
|
|
100
|
+
pcm = np.frombuffer(packet, '<i2', count=samples, offset=offset).copy()
|
|
101
|
+
faces = np.frombuffer(packet, np.uint8, offset=offset+samples*2).reshape(n, 112, 112).copy()
|
|
102
|
+
return metadata, pcm, faces
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class TalkNetWindows:
|
|
106
|
+
"""One face track and two declared same-clock lanes; no resampling or padding.
|
|
107
|
+
|
|
108
|
+
Face timestamps are interval ends at25fps; audio is capture-end mono16kPCM16.
|
|
109
|
+
push methods return zero or more immutable InputFrame byte packets.
|
|
110
|
+
"""
|
|
111
|
+
def __init__(self, *, clock_id, source_id='audiovisual', sensor_id='face-audio',
|
|
112
|
+
subject_id='local-user', window_frames=25, hop_frames=5):
|
|
113
|
+
for item in (clock_id, source_id, sensor_id, subject_id):
|
|
114
|
+
identifier(item)
|
|
115
|
+
if type(window_frames) is not int or window_frames not in (25, 50, 75, 100, 125, 150):
|
|
116
|
+
raise ValueError('window must be1..6whole seconds at25fps')
|
|
117
|
+
if type(hop_frames) is not int or not 1 <= hop_frames <= window_frames:
|
|
118
|
+
raise ValueError('hop must be1..window_frames')
|
|
119
|
+
import numpy as np
|
|
120
|
+
self.np = np
|
|
121
|
+
self.clock_id, self.source_id, self.sensor_id, self.subject_id = clock_id, source_id, sensor_id, subject_id
|
|
122
|
+
self.window_frames, self.hop_frames = window_frames, hop_frames
|
|
123
|
+
self._lock = threading.RLock()
|
|
124
|
+
self.closed = False
|
|
125
|
+
self._emitted = self._resets = self._prefix_drops = 0
|
|
126
|
+
self._reason = 'initial'
|
|
127
|
+
self._clear()
|
|
128
|
+
|
|
129
|
+
def _clear(self):
|
|
130
|
+
self._audio, self._video = {}, {}
|
|
131
|
+
self._owners, self._last = {}, {}
|
|
132
|
+
self._track = self._next = None
|
|
133
|
+
self._session = uuid.uuid4().hex
|
|
134
|
+
self._sequence = 0
|
|
135
|
+
|
|
136
|
+
def _reset(self, reason):
|
|
137
|
+
self._clear()
|
|
138
|
+
self._resets += 1
|
|
139
|
+
self._reason = reason
|
|
140
|
+
|
|
141
|
+
def reset(self):
|
|
142
|
+
with self._lock:
|
|
143
|
+
self._reset('explicit')
|
|
144
|
+
|
|
145
|
+
def close(self):
|
|
146
|
+
with self._lock:
|
|
147
|
+
self._clear()
|
|
148
|
+
self.closed = True
|
|
149
|
+
|
|
150
|
+
def status(self):
|
|
151
|
+
with self._lock:
|
|
152
|
+
return dict(closed=self.closed, session_id=self._session, emitted=self._emitted,
|
|
153
|
+
resets=self._resets, last_reset_reason=self._reason,
|
|
154
|
+
unsupported_prefix_face_frames=self._prefix_drops,
|
|
155
|
+
buffered_audio_ms=len(self._audio)*10, buffered_face_frames=len(self._video),
|
|
156
|
+
synchronization_verified=False)
|
|
157
|
+
|
|
158
|
+
def _frame(self, frame, lane, clock_id, duration):
|
|
159
|
+
if self.closed:
|
|
160
|
+
raise RuntimeError('audiovisual assembler is closed')
|
|
161
|
+
if (clock_id != self.clock_id or not isinstance(frame, InputFrame) or
|
|
162
|
+
frame.modality != lane or frame.subject_id != self.subject_id or
|
|
163
|
+
not isinstance(frame.sensor, SensorMetadata) or
|
|
164
|
+
type(frame.timestamp_ms) is not int or not duration <= frame.timestamp_ms <= 2**53-1):
|
|
165
|
+
raise ValueError('same-clock capture-end frame/subject metadata required')
|
|
166
|
+
sensor = frame.sensor
|
|
167
|
+
owner = _sensor(sensor)
|
|
168
|
+
seq = sensor.capture_sequence if sensor.capture_sequence is not None else sensor.sequence
|
|
169
|
+
previous = self._last.get(lane)
|
|
170
|
+
if lane in self._owners and owner != self._owners[lane]:
|
|
171
|
+
self._reset('source_changed')
|
|
172
|
+
elif previous:
|
|
173
|
+
if frame.timestamp_ms <= previous[0] or seq <= previous[1]:
|
|
174
|
+
raise ValueError('audiovisual capture order must increase')
|
|
175
|
+
if frame.timestamp_ms-duration != previous[0] or seq != previous[1]+1:
|
|
176
|
+
self._reset('capture_gap')
|
|
177
|
+
self._owners[lane] = owner
|
|
178
|
+
self._last[lane] = (frame.timestamp_ms, seq)
|
|
179
|
+
return seq
|
|
180
|
+
|
|
181
|
+
def push_audio(self, frame, *, clock_id):
|
|
182
|
+
with self._lock:
|
|
183
|
+
try:
|
|
184
|
+
if not isinstance(frame, InputFrame) or frame.sample_rate != 16000 or type(frame.sample_rate) is not int:
|
|
185
|
+
raise ValueError('16kHz PCM16 frame required')
|
|
186
|
+
data = frame.data
|
|
187
|
+
if type(data) is bytes:
|
|
188
|
+
if not 320 <= len(data) <= 32000 or len(data) % 320:
|
|
189
|
+
raise ValueError('audio must be10..1000ms in whole10ms blocks')
|
|
190
|
+
data = self.np.frombuffer(data, '<i2').copy()
|
|
191
|
+
elif (type(data) is not self.np.ndarray or data.dtype != self.np.dtype('int16') or
|
|
192
|
+
data.ndim != 1 or not 160 <= len(data) <= 16000 or len(data) % 160):
|
|
193
|
+
raise ValueError('mono int16 audio must be10..1000ms in whole10ms blocks')
|
|
194
|
+
else:
|
|
195
|
+
data = data.copy()
|
|
196
|
+
if not isinstance(frame.sensor, SensorMetadata) or len(frame.sensor.channels) != 1:
|
|
197
|
+
raise ValueError('one explicit mono channel required')
|
|
198
|
+
duration = len(data)//16
|
|
199
|
+
seq = self._frame(frame, 'audio', clock_id, duration)
|
|
200
|
+
if len(self._audio)+duration//10 > self.window_frames*4+100:
|
|
201
|
+
self._reset('buffer_overflow')
|
|
202
|
+
seq = self._frame(frame, 'audio', clock_id, duration)
|
|
203
|
+
start = frame.timestamp_ms-duration
|
|
204
|
+
for index in range(duration//10):
|
|
205
|
+
self._audio[start+index*10] = (data[index*160:(index+1)*160].copy(), seq)
|
|
206
|
+
return self._drain()
|
|
207
|
+
except Exception:
|
|
208
|
+
self._reset('invalid_audio')
|
|
209
|
+
raise
|
|
210
|
+
|
|
211
|
+
def push_face(self, frame, *, track_id, clock_id):
|
|
212
|
+
with self._lock:
|
|
213
|
+
try:
|
|
214
|
+
identifier(track_id, 'track_id')
|
|
215
|
+
if self._track is not None and track_id != self._track:
|
|
216
|
+
self._reset('track_changed')
|
|
217
|
+
seq = self._frame(frame, 'video', clock_id, 40)
|
|
218
|
+
if frame.data is None:
|
|
219
|
+
self._reset('face_absent')
|
|
220
|
+
return []
|
|
221
|
+
data = frame.data
|
|
222
|
+
if type(data) is not self.np.ndarray or data.dtype != self.np.uint8 or data.shape != (112, 112):
|
|
223
|
+
raise ValueError('explicit112x112grayscale uint8 face crop required')
|
|
224
|
+
start = frame.timestamp_ms-40
|
|
225
|
+
if self._next is not None and start < self._next:
|
|
226
|
+
self._prefix_drops += 1
|
|
227
|
+
return []
|
|
228
|
+
if len(self._video)+1 > self.window_frames+25:
|
|
229
|
+
self._reset('buffer_overflow')
|
|
230
|
+
seq = self._frame(frame, 'video', clock_id, 40)
|
|
231
|
+
self._track = track_id
|
|
232
|
+
start = frame.timestamp_ms-40
|
|
233
|
+
self._video[start] = (data.copy(), seq)
|
|
234
|
+
if self._next is None:
|
|
235
|
+
self._next = start
|
|
236
|
+
return self._drain()
|
|
237
|
+
except Exception:
|
|
238
|
+
self._reset('invalid_video')
|
|
239
|
+
raise
|
|
240
|
+
|
|
241
|
+
def _drain(self):
|
|
242
|
+
if not self._audio or self._next is None:
|
|
243
|
+
return []
|
|
244
|
+
if (min(self._audio)-self._next) % 10:
|
|
245
|
+
raise ValueError('audio/video clock grids do not align; calibrate upstream')
|
|
246
|
+
# Earlier audio cannot arrive in an ordered lane. Discard unsupported
|
|
247
|
+
# prefix face frames instead of manufacturing silence or shifting audio.
|
|
248
|
+
if self._next < min(self._audio):
|
|
249
|
+
steps = (min(self._audio)-self._next+39)//40
|
|
250
|
+
self._next += steps*40
|
|
251
|
+
self._prefix_drops += sum(k < self._next for k in self._video)
|
|
252
|
+
self._video = {k: v for k, v in self._video.items() if k >= self._next}
|
|
253
|
+
# Neither lane needs media before the next possible window. Keeping an
|
|
254
|
+
# unsupported audio prefix could trigger overflow just before a match.
|
|
255
|
+
self._audio = {k: v for k, v in self._audio.items() if k >= self._next}
|
|
256
|
+
output = []
|
|
257
|
+
n = self.window_frames
|
|
258
|
+
while True:
|
|
259
|
+
start = self._next
|
|
260
|
+
video_keys = range(start, start+n*40, 40)
|
|
261
|
+
audio_keys = range(start, start+n*40+20, 10)
|
|
262
|
+
if not all(k in self._video for k in video_keys) or not all(k in self._audio for k in audio_keys):
|
|
263
|
+
break
|
|
264
|
+
video = [self._video[k] for k in video_keys]
|
|
265
|
+
audio = [self._audio[k] for k in audio_keys]
|
|
266
|
+
pcm = self.np.concatenate([v[0] for v in audio])[:n*640+240].astype('<i2', copy=False)
|
|
267
|
+
faces = self.np.stack([v[0] for v in video])
|
|
268
|
+
meta = dict(version=1, clock_id=self.clock_id, session_id=self._session,
|
|
269
|
+
track_id=self._track, subject_id=self.subject_id, start_ms=start,
|
|
270
|
+
video_end_ms=start+n*40, audio_end_ms=start+n*40+15, frames=n,
|
|
271
|
+
audio_sensor=self._owners['audio'], video_sensor=self._owners['video'],
|
|
272
|
+
audio_sequence=[audio[0][1], audio[-1][1]], video_sequence=[video[0][1], video[-1][1]],
|
|
273
|
+
synchronization_verified=False, identity_verified=False)
|
|
274
|
+
packet = _encode(meta, pcm.tobytes(), faces.tobytes())
|
|
275
|
+
sensor = SensorMetadata(self.source_id, self.sensor_id, self._emitted,
|
|
276
|
+
channels=('mono',), stream_epoch=self._session)
|
|
277
|
+
output.append(InputFrame(packet, 'video', meta['audio_end_ms'], self.subject_id, 16000, sensor))
|
|
278
|
+
self._sequence += 1
|
|
279
|
+
self._emitted += 1
|
|
280
|
+
self._next += self.hop_frames*40
|
|
281
|
+
self._audio = {k: v for k, v in self._audio.items() if k >= self._next}
|
|
282
|
+
self._video = {k: v for k, v in self._video.items() if k >= self._next}
|
|
283
|
+
return output
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def talknet_stream_frame(frame):
|
|
287
|
+
"""Bind an assembler packet to SensorStreams' separate runtime epoch.
|
|
288
|
+
|
|
289
|
+
The capture session remains inside the immutable packet. Reopen the stream
|
|
290
|
+
when replacing the assembler instance, whose lifetime sequence starts at0.
|
|
291
|
+
"""
|
|
292
|
+
if not isinstance(frame, InputFrame) or not isinstance(frame.sensor, SensorMetadata):
|
|
293
|
+
raise ValueError('assembler InputFrame required')
|
|
294
|
+
meta, _, _ = decode_talknet_window(frame.data)
|
|
295
|
+
if (frame.modality != 'video' or type(frame.timestamp_ms) is not int or
|
|
296
|
+
frame.timestamp_ms != meta['audio_end_ms'] or frame.subject_id != meta['subject_id'] or
|
|
297
|
+
type(frame.sample_rate) is not int or frame.sample_rate != 16000 or
|
|
298
|
+
frame.sensor.stream_epoch != meta['session_id'] or frame.sensor.channels != ('mono',)):
|
|
299
|
+
raise ValueError('assembler packet provenance mismatch')
|
|
300
|
+
return replace(frame, sensor=replace(frame.sensor, stream_epoch=None))
|
gamst/cadence.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Passive connection-local context delivery profiling, never LLM calibration."""
|
|
2
|
+
from collections import deque
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ContextCadenceProfile:
|
|
7
|
+
def __init__(self, interval_ms=None):
|
|
8
|
+
if interval_ms is not None and (type(interval_ms) is not int or not 50 <= interval_ms <= 60000):
|
|
9
|
+
raise ValueError('interval_ms must be 50..60000')
|
|
10
|
+
self.interval_ms = interval_ms
|
|
11
|
+
self.running = False
|
|
12
|
+
self.samples = deque(maxlen=64)
|
|
13
|
+
self.gaps = deque(maxlen=64)
|
|
14
|
+
self.completed = 0
|
|
15
|
+
self.last_completion = None
|
|
16
|
+
self.failures = 0
|
|
17
|
+
|
|
18
|
+
def record(self, work_ms, completion_ms):
|
|
19
|
+
if any(type(v) not in (int, float) or not math.isfinite(v) or v < 0
|
|
20
|
+
for v in (work_ms, completion_ms)):
|
|
21
|
+
raise ValueError('profile samples must be finite nonnegative milliseconds')
|
|
22
|
+
if self.last_completion is not None and completion_ms < self.last_completion:
|
|
23
|
+
raise ValueError('completion clock moved backwards')
|
|
24
|
+
if self.last_completion is not None:
|
|
25
|
+
self.gaps.append(completion_ms-self.last_completion)
|
|
26
|
+
self.last_completion = completion_ms
|
|
27
|
+
self.samples.append(work_ms)
|
|
28
|
+
self.completed += 1
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def _summary(values):
|
|
32
|
+
if not values:
|
|
33
|
+
return None
|
|
34
|
+
ordered = sorted(values)
|
|
35
|
+
return dict(p50_ms=ordered[math.ceil(len(ordered)*.5)-1],
|
|
36
|
+
p95_ms=ordered[math.ceil(len(ordered)*.95)-1])
|
|
37
|
+
|
|
38
|
+
def snapshot(self):
|
|
39
|
+
work = self._summary(self.samples)
|
|
40
|
+
enough = len(self.samples) >= 8
|
|
41
|
+
desired = max(50, math.ceil(work['p95_ms'])) if enough else None
|
|
42
|
+
return dict(requested_interval_ms=self.interval_ms,
|
|
43
|
+
applied_interval_ms=self.interval_ms,
|
|
44
|
+
recommended_interval_ms=min(60000, desired) if enough else None,
|
|
45
|
+
recommendation_exceeds_supported_range=desired > 60000 if enough else False,
|
|
46
|
+
recommendation_basis='heuristic: idle at least rolling p95 generation+send time; minimum 8 completions',
|
|
47
|
+
interval_semantics='idle delay after completed send; not a guaranteed delivery period',
|
|
48
|
+
configured=self.interval_ms is not None, running=self.running,
|
|
49
|
+
completed=self.completed, failures=self.failures, retained_samples=len(self.samples),
|
|
50
|
+
work=work, observed_completion_intervals=self._summary(self.gaps),
|
|
51
|
+
consumer_comprehension='unknown', consumer_input_capacity='unknown',
|
|
52
|
+
automatic_application=False, probes_sent=0)
|
gamst/calibrate.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Fit and validate an empirical score calibration from two labeled JSONL files."""
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from .feedback import LabeledOutcome, fit_calibration
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def read_labels(path):
|
|
9
|
+
with Path(path).open(encoding='utf-8') as handle:
|
|
10
|
+
for line_no, line in enumerate(handle, 1):
|
|
11
|
+
if not line.strip():
|
|
12
|
+
continue
|
|
13
|
+
try:
|
|
14
|
+
item = json.loads(line)
|
|
15
|
+
if not isinstance(item, dict) or set(item) != {'id', 'score', 'outcome'}:
|
|
16
|
+
raise ValueError('Expected exactly id, score, outcome')
|
|
17
|
+
yield LabeledOutcome(**item)
|
|
18
|
+
except (ValueError, TypeError) as exc:
|
|
19
|
+
raise ValueError(f'{path}:{line_no}: {exc}') from exc
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
24
|
+
parser.add_argument('--training', required=True)
|
|
25
|
+
parser.add_argument('--validation', required=True)
|
|
26
|
+
parser.add_argument('--training-dataset', required=True)
|
|
27
|
+
parser.add_argument('--validation-dataset', required=True)
|
|
28
|
+
parser.add_argument('--target', required=True)
|
|
29
|
+
parser.add_argument('--scorer-model-id', required=True)
|
|
30
|
+
parser.add_argument('--scorer-model-version', required=True)
|
|
31
|
+
parser.add_argument('--output', required=True)
|
|
32
|
+
args = parser.parse_args()
|
|
33
|
+
if Path(args.training).resolve() == Path(args.validation).resolve():
|
|
34
|
+
parser.error('Training and validation must be different files')
|
|
35
|
+
if Path(args.output).exists():
|
|
36
|
+
parser.error('Output exists; choose a new artifact path')
|
|
37
|
+
if args.training_dataset == args.validation_dataset:
|
|
38
|
+
parser.error('Training and validation datasets must differ')
|
|
39
|
+
try:
|
|
40
|
+
artifact = fit_calibration(target=args.target, training=read_labels(args.training),
|
|
41
|
+
validation=read_labels(args.validation), training_dataset=args.training_dataset,
|
|
42
|
+
validation_dataset=args.validation_dataset, scorer_model_id=args.scorer_model_id,
|
|
43
|
+
scorer_model_version=args.scorer_model_version)
|
|
44
|
+
# Exclusive creation protects labels or a prior model from accidental overwrite.
|
|
45
|
+
with Path(args.output).open('x', encoding='utf-8') as handle:
|
|
46
|
+
handle.write(artifact.to_json()+'\n')
|
|
47
|
+
except (ValueError, OSError, TypeError) as exc:
|
|
48
|
+
parser.exit(2, f'{exc}\n')
|
|
49
|
+
print(json.dumps({'artifact': str(args.output), 'evaluation': artifact.evaluation}, indent=2))
|
|
50
|
+
return 0 if artifact.validated else 1
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == '__main__':
|
|
54
|
+
raise SystemExit(main())
|