Skip to content

Commit 87e9341

Browse files
committed
style: apply pre-commit black/isort formatting to imported WIP modules
1 parent 1a3de8a commit 87e9341

32 files changed

Lines changed: 259 additions & 125 deletions

backends/advanced/src/advanced_omi_backend/controllers/background_bucket_controller.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131
from rq.job import Job
3232

3333
from advanced_omi_backend.constants import BACKGROUND_SPEECH_LABEL, NOISE_LABEL
34-
from advanced_omi_backend.models.conversation import Conversation
3534
from advanced_omi_backend.controllers.queue_controller import (
3635
JOB_RESULT_TTL,
3736
default_queue,
3837
)
38+
from advanced_omi_backend.models.conversation import Conversation
3939
from advanced_omi_backend.speaker_recognition_client import SpeakerRecognitionClient
4040
from advanced_omi_backend.users import User
4141
from advanced_omi_backend.utils.audio_chunk_utils import reconstruct_audio_segment
42-
from advanced_omi_backend.workers.background_index_jobs import (
43-
index_background_corpus_job,
44-
)
42+
from advanced_omi_backend.workers.background_benchmark import build_background_benchmark
4543
from advanced_omi_backend.workers.background_cleanup_jobs import (
4644
apply_background_cleanup_job,
4745
build_background_cleanup_report,
4846
)
49-
from advanced_omi_backend.workers.background_benchmark import build_background_benchmark
47+
from advanced_omi_backend.workers.background_index_jobs import (
48+
index_background_corpus_job,
49+
)
5050
from advanced_omi_backend.workers.background_suppression import zone_for
5151

5252
logger = logging.getLogger(__name__)
@@ -887,9 +887,7 @@ def _novelty_groups(
887887
):
888888
groups.setdefault(row["conversation_id"], []).append(row)
889889
return [
890-
group
891-
for group in groups.values()
892-
if len(group) >= profile["novelty_min_clips"]
890+
group for group in groups.values() if len(group) >= profile["novelty_min_clips"]
893891
]
894892

895893

backends/advanced/src/advanced_omi_backend/controllers/background_suppression_controller.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ async def get_conversation_suppressions(user: User, conversation_id: str) -> dic
5959
},
6060
)
6161
cluster["segments"].append(doc)
62-
cluster["statuses"][doc["status"]] = cluster["statuses"].get(doc["status"], 0) + 1
62+
cluster["statuses"][doc["status"]] = (
63+
cluster["statuses"].get(doc["status"], 0) + 1
64+
)
6365
cluster["zones"][doc["zone"]] = cluster["zones"].get(doc["zone"], 0) + 1
6466
cluster["max_background_similarity"] = max(
6567
cluster["max_background_similarity"],

backends/advanced/src/advanced_omi_backend/controllers/drift_controller.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ async def drift_fingerprint() -> str:
8989
"id": "$$v.version_id",
9090
"cent": {
9191
"$cond": [
92-
{"$ifNull": ["$$v.metadata.cluster_centroids", False]},
92+
{
93+
"$ifNull": [
94+
"$$v.metadata.cluster_centroids",
95+
False,
96+
]
97+
},
9398
1,
9499
0,
95100
]
@@ -116,7 +121,11 @@ async def drift_fingerprint() -> str:
116121
convs = []
117122
async for doc in Conversation.get_pymongo_collection().aggregate(pipeline):
118123
active = next(
119-
(v for v in doc["versions"] if v["id"] == doc.get("active_transcript_version")),
124+
(
125+
v
126+
for v in doc["versions"]
127+
if v["id"] == doc.get("active_transcript_version")
128+
),
120129
None,
121130
)
122131
convs.append(

backends/advanced/src/advanced_omi_backend/controllers/guided_enrollment_controller.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ async def _candidate_pool(user: User, speaker_name: str, reviewed: set) -> list:
206206
},
207207
):
208208
segments = _active_segments(doc)
209-
speaker_present = any(
210-
_effective_label(s) == speaker_name for s in segments
211-
)
209+
speaker_present = any(_effective_label(s) == speaker_name for s in segments)
212210
if not speaker_present:
213211
continue
214212
audio_duration = doc.get("audio_total_duration") or 0.0

backends/advanced/src/advanced_omi_backend/routers/modules/device_input_routes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def _utc_iso(value: Optional[datetime]) -> Optional[str]:
7373
return _as_utc(value).isoformat().replace("+00:00", "Z")
7474

7575

76-
def _effective_source_status(source: CaptureSource, now: Optional[datetime] = None) -> str:
76+
def _effective_source_status(
77+
source: CaptureSource, now: Optional[datetime] = None
78+
) -> str:
7779
if source.status != "online":
7880
return source.status
7981
checked_at = _as_utc(now or utcnow())
@@ -242,7 +244,11 @@ async def ingest_activity(
242244
start_at=incoming.captured_at,
243245
end_at=incoming.ended_at,
244246
purpose="timeline_thumbnail",
245-
payload={"item_id": str(item.id), "frame_id": frame_id, "width": 960},
247+
payload={
248+
"item_id": str(item.id),
249+
"frame_id": frame_id,
250+
"width": 960,
251+
},
246252
).insert()
247253
except DuplicateKeyError:
248254
duplicates += 1

backends/advanced/src/advanced_omi_backend/workers/background_suppression_jobs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ async def backfill_conversation_suppressions(
136136

137137
async def backfill_all_suppressions(user_id: str, limit: int = 500) -> dict:
138138
"""Backfill every conversation present in the corpus index."""
139-
conversation_ids = await (
140-
_database()["background_corpus_embeddings"]
141-
.distinct("conversation_id", {"requested_by": user_id})
139+
conversation_ids = await _database()["background_corpus_embeddings"].distinct(
140+
"conversation_id", {"requested_by": user_id}
142141
)
143142
results = {"conversations": 0, "written": 0, "skipped": 0}
144143
for conversation_id in conversation_ids[:limit]:

backends/advanced/src/scripts/cleanup_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,21 @@ def row(label, value, style="white"):
243243
str(stats.langfuse_prompts),
244244
"yellow" if stats.langfuse_prompts else "dim",
245245
)
246-
"""table.add_section() #then
246+
"""table.add_section() #then
247247
row("Redis Jobs", str(stats.redis_jobs), "dim")
248248
row("Legacy WAV Files", str(stats.legacy_wav), "dim")
249249
row("Vault Files", str(stats.vault_files), "green" if stats.vault_files else "dim")
250250
table.add_section()
251251
row("Users", str(stats.users), "cyan")
252252
253253
return table"""
254-
#now
254+
# now
255255
table.add_section()
256256
row("Redis Jobs", str(stats.redis_jobs), "dim")
257257
row("Legacy WAV Files", str(stats.legacy_wav), "dim")
258258
row("Vault Files", str(stats.vault_files), "green" if stats.vault_files else "dim")
259259
table.add_section()
260-
260+
261261
# ----------------------------------------------------
262262
# Custom Extension: Disk Storage Metric
263263
# Added by Omer Said Bayhan (https://github.com/omer-said-bayhan)

backends/advanced/tests/test_background_buckets.py

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from advanced_omi_backend.constants import is_non_enrollable_speaker
55
from advanced_omi_backend.controllers.background_bucket_controller import (
6+
SURFACE_PROFILES,
67
_background_likelihood,
78
_cluster_rows,
89
_content_signature,
@@ -12,20 +13,18 @@
1213
_is_known_foreground,
1314
_max_similarity,
1415
_novelty_groups,
15-
_representatives,
16+
_queue_summary,
1617
_reference_scores,
18+
_representatives,
1719
_review_samples,
18-
_queue_summary,
19-
SURFACE_PROFILES,
2020
)
2121
from advanced_omi_backend.models.conversation import Conversation
2222
from advanced_omi_backend.routers.modules.annotation_routes import (
2323
_apply_diarization_label,
2424
)
25-
from advanced_omi_backend.workers import speaker_jobs
26-
from advanced_omi_backend.workers import background_index_jobs
27-
from advanced_omi_backend.workers.background_cleanup_jobs import _score_rows
25+
from advanced_omi_backend.workers import background_index_jobs, speaker_jobs
2826
from advanced_omi_backend.workers.background_benchmark import evaluate_reviews
27+
from advanced_omi_backend.workers.background_cleanup_jobs import _score_rows
2928

3029

3130
def test_gap_windows_sample_audio_without_transcript_segments():
@@ -172,9 +171,21 @@ def test_not_background_examples_suppress_similar_speech_but_not_noise():
172171

173172
def test_confirmed_background_mines_similar_clips_for_batch_harvest():
174173
rows = [
175-
{"clip_key": "a", "conversation_id": "one", "candidate_type": "background_speech"},
176-
{"clip_key": "b", "conversation_id": "one", "candidate_type": "background_speech"},
177-
{"clip_key": "c", "conversation_id": "two", "candidate_type": "background_speech"},
174+
{
175+
"clip_key": "a",
176+
"conversation_id": "one",
177+
"candidate_type": "background_speech",
178+
},
179+
{
180+
"clip_key": "b",
181+
"conversation_id": "one",
182+
"candidate_type": "background_speech",
183+
},
184+
{
185+
"clip_key": "c",
186+
"conversation_id": "two",
187+
"candidate_type": "background_speech",
188+
},
178189
{"clip_key": "d", "conversation_id": "one", "candidate_type": "noise"},
179190
]
180191
background = {"a": 0.9, "b": 0.6, "c": 0.4, "d": 0.9}
@@ -188,7 +199,11 @@ def test_confirmed_background_mines_similar_clips_for_batch_harvest():
188199

189200
def test_harvest_requires_background_to_beat_foreground_by_margin():
190201
rows = [
191-
{"clip_key": "a", "conversation_id": "one", "candidate_type": "background_speech"},
202+
{
203+
"clip_key": "a",
204+
"conversation_id": "one",
205+
"candidate_type": "background_speech",
206+
},
192207
]
193208

194209
# familiar foreground voice that also happens to resemble the bucket
@@ -198,13 +213,29 @@ def test_harvest_requires_background_to_beat_foreground_by_margin():
198213
def test_queue_summary_splits_sign_offs_from_genuine_unknowns():
199214
clusters = [
200215
# harvest lane: quick confirm regardless of mean scores
201-
{"mined": "harvest", "mean_background_similarity": 0.5, "mean_foreground_similarity": 0.4},
216+
{
217+
"mined": "harvest",
218+
"mean_background_similarity": 0.5,
219+
"mean_foreground_similarity": 0.4,
220+
},
202221
# confident zone (>=0.45 and margin >=0.20): quick confirm
203-
{"mined": None, "mean_background_similarity": 0.6, "mean_foreground_similarity": 0.3},
222+
{
223+
"mined": None,
224+
"mean_background_similarity": 0.6,
225+
"mean_foreground_similarity": 0.3,
226+
},
204227
# unsure band: genuinely uncertain
205-
{"mined": None, "mean_background_similarity": 0.45, "mean_foreground_similarity": 0.35},
228+
{
229+
"mined": None,
230+
"mean_background_similarity": 0.45,
231+
"mean_foreground_similarity": 0.35,
232+
},
206233
# novelty (low similarity to everything): genuinely uncertain
207-
{"mined": "novel", "mean_background_similarity": 0.1, "mean_foreground_similarity": 0.1},
234+
{
235+
"mined": "novel",
236+
"mean_background_similarity": 0.1,
237+
"mean_foreground_similarity": 0.1,
238+
},
208239
]
209240

210241
assert _queue_summary(clusters) == {
@@ -216,31 +247,49 @@ def test_queue_summary_splits_sign_offs_from_genuine_unknowns():
216247

217248
def test_surface_dial_widens_and_narrows_the_harvest_lane():
218249
rows = [
219-
{"clip_key": "a", "conversation_id": "one", "candidate_type": "background_speech"},
250+
{
251+
"clip_key": "a",
252+
"conversation_id": "one",
253+
"candidate_type": "background_speech",
254+
},
220255
]
221256
# borderline clip: below the default 0.55 floor, above the "more" 0.45 one
222257
background = {"a": 0.50}
223258
foreground = {"a": 0.30}
224259

225260
assert _harvest_groups(rows, background, foreground) == []
226-
assert _harvest_groups(
227-
rows, background, foreground, SURFACE_PROFILES["more"]
228-
) == [[rows[0]]]
261+
assert _harvest_groups(rows, background, foreground, SURFACE_PROFILES["more"]) == [
262+
[rows[0]]
263+
]
229264
# "less" tightens past a clip the default would accept
230-
assert _harvest_groups(
231-
rows, {"a": 0.58}, {"a": 0.30}, SURFACE_PROFILES["less"]
232-
) == []
265+
assert (
266+
_harvest_groups(rows, {"a": 0.58}, {"a": 0.30}, SURFACE_PROFILES["less"]) == []
267+
)
233268

234269

235270
def test_novelty_lane_surfaces_clips_unlike_any_labelled_reference():
236271
rows = [
237-
{"clip_key": f"tv{i}", "conversation_id": "tv-conv", "candidate_type": "background_speech"}
272+
{
273+
"clip_key": f"tv{i}",
274+
"conversation_id": "tv-conv",
275+
"candidate_type": "background_speech",
276+
}
238277
for i in range(5)
239278
] + [
240-
{"clip_key": "familiar", "conversation_id": "tv-conv", "candidate_type": "background_speech"},
241-
{"clip_key": "lone", "conversation_id": "small-conv", "candidate_type": "background_speech"},
279+
{
280+
"clip_key": "familiar",
281+
"conversation_id": "tv-conv",
282+
"candidate_type": "background_speech",
283+
},
284+
{
285+
"clip_key": "lone",
286+
"conversation_id": "small-conv",
287+
"candidate_type": "background_speech",
288+
},
242289
]
243-
background = {key: 0.1 for key in ("tv0", "tv1", "tv2", "tv3", "tv4", "familiar", "lone")}
290+
background = {
291+
key: 0.1 for key in ("tv0", "tv1", "tv2", "tv3", "tv4", "familiar", "lone")
292+
}
244293
foreground = {key: 0.1 for key in background} | {"familiar": 0.8}
245294

246295
groups = _novelty_groups(rows, background, foreground, consumed={"tv4"})

backends/advanced/tests/test_background_suppression.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ def test_same_source_segments_share_a_cluster_signature():
4747

4848
def test_cluster_signatures_are_stable_across_rescoring():
4949
embeddings = [[1.0, 0.0], [0.98, 0.02]]
50-
first = [_record(10.0, "line one", embeddings[0]), _record(20.0, "line two", embeddings[1])]
51-
second = [_record(10.0, "line one", embeddings[0]), _record(20.0, "line two", embeddings[1])]
50+
first = [
51+
_record(10.0, "line one", embeddings[0]),
52+
_record(20.0, "line two", embeddings[1]),
53+
]
54+
second = [
55+
_record(10.0, "line one", embeddings[0]),
56+
_record(20.0, "line two", embeddings[1]),
57+
]
5258
assign_cluster_signatures(first)
5359
assign_cluster_signatures(second)
5460
assert first[0]["cluster_signature"] == second[0]["cluster_signature"]

backends/advanced/tests/test_guided_enrollment_pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ def test_placeholder_labels_are_not_attribution():
3434

3535
def _clip(sim, manually_labeled):
3636
return {
37-
"scores": {"sim_centroid": sim, "max_clip_sim": 0.4, "best_other": {"score": 0.1}},
37+
"scores": {
38+
"sim_centroid": sim,
39+
"max_clip_sim": 0.4,
40+
"best_other": {"score": 0.1},
41+
},
3842
"duration": 6.0,
3943
"current_label": "daksh",
4044
"manually_labeled": manually_labeled,

0 commit comments

Comments
 (0)