feat: add speaker mapping and workflow improvements
This commit is contained in:
@@ -18,6 +18,7 @@ class AppSettings:
|
||||
|
||||
data_root: Path
|
||||
whisper_model: Path | None
|
||||
glossary_database: Path = Path("data/database/glossary.sqlite3")
|
||||
whisper_executable: str = "whisper-cli"
|
||||
ffmpeg_executable: str = "ffmpeg"
|
||||
protocol_model: str = "qwen3.8:27b"
|
||||
@@ -40,9 +41,12 @@ class AppSettings:
|
||||
return cls(
|
||||
data_root=Path(os.getenv("MKA_DATA_ROOT", "data/meetings")),
|
||||
whisper_model=Path(whisper_model) if whisper_model else None,
|
||||
glossary_database=Path(
|
||||
os.getenv("MKA_GLOSSARY_DATABASE", "data/database/glossary.sqlite3")
|
||||
),
|
||||
whisper_executable=os.getenv("MKA_WHISPER_EXECUTABLE", "whisper-cli"),
|
||||
ffmpeg_executable=os.getenv("MKA_FFMPEG_EXECUTABLE", "ffmpeg"),
|
||||
protocol_model=os.getenv("MKA_PROTOCOL_MODEL", "qwen3.8:27B"),
|
||||
protocol_model=os.getenv("MKA_PROTOCOL_MODEL", "qwen3.8:27b"),
|
||||
ollama_endpoint=os.getenv("MKA_OLLAMA_ENDPOINT", "http://127.0.0.1:11434"),
|
||||
language=os.getenv("MKA_LANGUAGE", "de"),
|
||||
threads=parsed_threads,
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
"""SQLite-backed global terminology glossary."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from collections.abc import Iterable, Iterator
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
GLOSSARY_CATEGORIES = (
|
||||
"product",
|
||||
"material",
|
||||
"organization",
|
||||
"technical_term",
|
||||
"acronym",
|
||||
"other",
|
||||
)
|
||||
|
||||
|
||||
class GlossaryConflictError(ValueError):
|
||||
"""Raised when a canonical term or alias conflicts with existing terminology."""
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GlossaryEntry:
|
||||
id: int
|
||||
canonical_term: str
|
||||
category: str
|
||||
description: str | None
|
||||
is_active: bool
|
||||
aliases: tuple[str, ...]
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
class GlossaryRepository:
|
||||
"""Small data-access boundary for the local glossary database."""
|
||||
|
||||
def __init__(self, database_path: Path) -> None:
|
||||
self.database_path = Path(database_path)
|
||||
|
||||
def initialize(self) -> None:
|
||||
"""Create the database and current schema when absent."""
|
||||
self.database_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with self._connect() as connection:
|
||||
connection.executescript(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS glossary_entries (
|
||||
id INTEGER PRIMARY KEY,
|
||||
canonical_term TEXT NOT NULL COLLATE NOCASE UNIQUE,
|
||||
category TEXT NOT NULL CHECK (category IN (
|
||||
'product', 'material', 'organization',
|
||||
'technical_term', 'acronym', 'other'
|
||||
)),
|
||||
description TEXT,
|
||||
is_active INTEGER NOT NULL DEFAULT 1 CHECK (is_active IN (0, 1)),
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS glossary_aliases (
|
||||
id INTEGER PRIMARY KEY,
|
||||
entry_id INTEGER NOT NULL REFERENCES glossary_entries(id)
|
||||
ON DELETE CASCADE,
|
||||
alias TEXT NOT NULL COLLATE NOCASE UNIQUE,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_glossary_aliases_entry_id
|
||||
ON glossary_aliases(entry_id);
|
||||
PRAGMA user_version = 1;
|
||||
"""
|
||||
)
|
||||
|
||||
def create(
|
||||
self,
|
||||
canonical_term: str,
|
||||
category: str,
|
||||
*,
|
||||
aliases: Iterable[str] = (),
|
||||
description: str | None = None,
|
||||
is_active: bool = True,
|
||||
) -> GlossaryEntry:
|
||||
canonical, normalized_aliases = self._validate_values(canonical_term, category, aliases)
|
||||
now = _timestamp()
|
||||
try:
|
||||
with self._connect() as connection:
|
||||
self._ensure_terms_available(connection, canonical, normalized_aliases)
|
||||
cursor = connection.execute(
|
||||
"""INSERT INTO glossary_entries
|
||||
(canonical_term, category, description, is_active, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)""",
|
||||
(canonical, category, _optional_text(description), is_active, now, now),
|
||||
)
|
||||
entry_id = int(cursor.lastrowid)
|
||||
connection.executemany(
|
||||
"INSERT INTO glossary_aliases (entry_id, alias, created_at) VALUES (?, ?, ?)",
|
||||
((entry_id, alias, now) for alias in normalized_aliases),
|
||||
)
|
||||
except sqlite3.IntegrityError as exc:
|
||||
raise GlossaryConflictError("Canonical term or alias already exists.") from exc
|
||||
return self.get(entry_id)
|
||||
|
||||
def get(self, entry_id: int) -> GlossaryEntry:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
"SELECT * FROM glossary_entries WHERE id = ?", (entry_id,)
|
||||
).fetchone()
|
||||
if row is None:
|
||||
raise KeyError(f"Unknown glossary entry: {entry_id}")
|
||||
return self._to_entry(connection, row)
|
||||
|
||||
def list(self, search: str = "", *, active_only: bool = False) -> list[GlossaryEntry]:
|
||||
clauses: list[str] = []
|
||||
parameters: list[object] = []
|
||||
if active_only:
|
||||
clauses.append("entry.is_active = 1")
|
||||
if search.strip():
|
||||
clauses.append(
|
||||
"(entry.canonical_term LIKE ? COLLATE NOCASE "
|
||||
"OR entry.category LIKE ? COLLATE NOCASE "
|
||||
"OR entry.description LIKE ? COLLATE NOCASE "
|
||||
"OR alias.alias LIKE ? COLLATE NOCASE)"
|
||||
)
|
||||
pattern = f"%{search.strip()}%"
|
||||
parameters.extend([pattern] * 4)
|
||||
where = f"WHERE {' AND '.join(clauses)}" if clauses else ""
|
||||
with self._connect() as connection:
|
||||
rows = connection.execute(
|
||||
f"""SELECT DISTINCT entry.* FROM glossary_entries AS entry
|
||||
LEFT JOIN glossary_aliases AS alias ON alias.entry_id = entry.id
|
||||
{where} ORDER BY entry.canonical_term COLLATE NOCASE""", # noqa: S608
|
||||
parameters,
|
||||
).fetchall()
|
||||
return [self._to_entry(connection, row) for row in rows]
|
||||
|
||||
def update(
|
||||
self,
|
||||
entry_id: int,
|
||||
canonical_term: str,
|
||||
category: str,
|
||||
*,
|
||||
aliases: Iterable[str] = (),
|
||||
description: str | None = None,
|
||||
is_active: bool = True,
|
||||
) -> GlossaryEntry:
|
||||
canonical, normalized_aliases = self._validate_values(canonical_term, category, aliases)
|
||||
try:
|
||||
with self._connect() as connection:
|
||||
exists = connection.execute(
|
||||
"SELECT 1 FROM glossary_entries WHERE id = ?", (entry_id,)
|
||||
).fetchone()
|
||||
if exists is None:
|
||||
raise KeyError(f"Unknown glossary entry: {entry_id}")
|
||||
self._ensure_terms_available(
|
||||
connection, canonical, normalized_aliases, excluding_entry_id=entry_id
|
||||
)
|
||||
now = _timestamp()
|
||||
connection.execute(
|
||||
"""UPDATE glossary_entries SET canonical_term = ?, category = ?,
|
||||
description = ?, is_active = ?, updated_at = ? WHERE id = ?""",
|
||||
(
|
||||
canonical,
|
||||
category,
|
||||
_optional_text(description),
|
||||
is_active,
|
||||
now,
|
||||
entry_id,
|
||||
),
|
||||
)
|
||||
connection.execute("DELETE FROM glossary_aliases WHERE entry_id = ?", (entry_id,))
|
||||
connection.executemany(
|
||||
"INSERT INTO glossary_aliases (entry_id, alias, created_at) VALUES (?, ?, ?)",
|
||||
((entry_id, alias, now) for alias in normalized_aliases),
|
||||
)
|
||||
except sqlite3.IntegrityError as exc:
|
||||
raise GlossaryConflictError("Canonical term or alias already exists.") from exc
|
||||
return self.get(entry_id)
|
||||
|
||||
def set_active(self, entry_id: int, is_active: bool) -> GlossaryEntry:
|
||||
entry = self.get(entry_id)
|
||||
return self.update(
|
||||
entry.id,
|
||||
entry.canonical_term,
|
||||
entry.category,
|
||||
aliases=entry.aliases,
|
||||
description=entry.description,
|
||||
is_active=is_active,
|
||||
)
|
||||
|
||||
def delete(self, entry_id: int) -> None:
|
||||
with self._connect() as connection:
|
||||
cursor = connection.execute("DELETE FROM glossary_entries WHERE id = ?", (entry_id,))
|
||||
if cursor.rowcount == 0:
|
||||
raise KeyError(f"Unknown glossary entry: {entry_id}")
|
||||
|
||||
@contextmanager
|
||||
def _connect(self) -> Iterator[sqlite3.Connection]:
|
||||
connection = sqlite3.connect(self.database_path, timeout=5)
|
||||
try:
|
||||
connection.row_factory = sqlite3.Row
|
||||
connection.execute("PRAGMA foreign_keys = ON")
|
||||
connection.execute("PRAGMA journal_mode = WAL")
|
||||
connection.execute("PRAGMA busy_timeout = 5000")
|
||||
with connection:
|
||||
yield connection
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
@staticmethod
|
||||
def _validate_values(
|
||||
canonical_term: str, category: str, aliases: Iterable[str]
|
||||
) -> tuple[str, tuple[str, ...]]:
|
||||
canonical = canonical_term.strip()
|
||||
if not canonical:
|
||||
raise ValueError("Canonical term is required.")
|
||||
if category not in GLOSSARY_CATEGORIES:
|
||||
raise ValueError(f"Unsupported glossary category: {category}")
|
||||
normalized_aliases = tuple(
|
||||
dict.fromkeys(alias.strip() for alias in aliases if alias.strip())
|
||||
)
|
||||
folded = [alias.casefold() for alias in normalized_aliases]
|
||||
if len(folded) != len(set(folded)) or canonical.casefold() in folded:
|
||||
raise GlossaryConflictError(
|
||||
"Aliases must be unique and differ from the canonical term."
|
||||
)
|
||||
return canonical, normalized_aliases
|
||||
|
||||
@staticmethod
|
||||
def _ensure_terms_available(
|
||||
connection: sqlite3.Connection,
|
||||
canonical: str,
|
||||
aliases: tuple[str, ...],
|
||||
*,
|
||||
excluding_entry_id: int | None = None,
|
||||
) -> None:
|
||||
terms = (canonical, *aliases)
|
||||
placeholders = ", ".join("?" for _ in terms)
|
||||
exclusion = "AND entry_id != ?" if excluding_entry_id is not None else ""
|
||||
alias_parameters: list[object] = [*terms]
|
||||
if excluding_entry_id is not None:
|
||||
alias_parameters.append(excluding_entry_id)
|
||||
alias_conflict = connection.execute(
|
||||
f"SELECT 1 FROM glossary_aliases WHERE alias IN ({placeholders}) {exclusion} LIMIT 1", # noqa: S608
|
||||
alias_parameters,
|
||||
).fetchone()
|
||||
entry_exclusion = "AND id != ?" if excluding_entry_id is not None else ""
|
||||
entry_parameters: list[object] = [*terms]
|
||||
if excluding_entry_id is not None:
|
||||
entry_parameters.append(excluding_entry_id)
|
||||
canonical_conflict = connection.execute(
|
||||
f"SELECT 1 FROM glossary_entries WHERE canonical_term IN ({placeholders}) " # noqa: S608
|
||||
f"{entry_exclusion} LIMIT 1",
|
||||
entry_parameters,
|
||||
).fetchone()
|
||||
if alias_conflict or canonical_conflict:
|
||||
raise GlossaryConflictError("Canonical term or alias already exists.")
|
||||
|
||||
@staticmethod
|
||||
def _to_entry(connection: sqlite3.Connection, row: sqlite3.Row) -> GlossaryEntry:
|
||||
aliases = connection.execute(
|
||||
"SELECT alias FROM glossary_aliases WHERE entry_id = ? ORDER BY alias COLLATE NOCASE",
|
||||
(row["id"],),
|
||||
).fetchall()
|
||||
return GlossaryEntry(
|
||||
id=row["id"],
|
||||
canonical_term=row["canonical_term"],
|
||||
category=row["category"],
|
||||
description=row["description"],
|
||||
is_active=bool(row["is_active"]),
|
||||
aliases=tuple(alias["alias"] for alias in aliases),
|
||||
created_at=row["created_at"],
|
||||
updated_at=row["updated_at"],
|
||||
)
|
||||
|
||||
|
||||
def render_glossary_terms(entries: Iterable[GlossaryEntry]) -> list[str]:
|
||||
"""Render concise canonical terms with recognition aliases for Meeting Context."""
|
||||
rendered = []
|
||||
for entry in entries:
|
||||
item = entry.canonical_term
|
||||
if entry.aliases:
|
||||
item += f" (aliases: {', '.join(entry.aliases)})"
|
||||
rendered.append(item)
|
||||
return rendered
|
||||
|
||||
|
||||
def _timestamp() -> str:
|
||||
return datetime.now(UTC).isoformat(timespec="seconds")
|
||||
|
||||
|
||||
def _optional_text(value: str | None) -> str | None:
|
||||
stripped = value.strip() if value else ""
|
||||
return stripped or None
|
||||
@@ -12,7 +12,10 @@ from pathlib import Path
|
||||
from typing import Any, Protocol
|
||||
from uuid import uuid4
|
||||
|
||||
import yaml
|
||||
|
||||
from mka.application.config import AppSettings
|
||||
from mka.application.glossary import GlossaryRepository, render_glossary_terms
|
||||
|
||||
STAGES = ("preparing", "transcription", "diarization", "protocol_generation")
|
||||
|
||||
@@ -31,6 +34,14 @@ class MeetingLabPort(Protocol):
|
||||
progress_sink: Callable[[Any], None],
|
||||
) -> Any: ...
|
||||
|
||||
def regenerate_protocol(
|
||||
self,
|
||||
run_dir: Path,
|
||||
meeting_context: Any,
|
||||
progress_sink: Callable[[Any], None],
|
||||
**options: Any,
|
||||
) -> Any: ...
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MeetingDetails:
|
||||
@@ -73,6 +84,20 @@ class ProcessingOutcome:
|
||||
protocol_path: Path | None
|
||||
failed_stage: str | None = None
|
||||
error_message: str | None = None
|
||||
speaker_attribution_available: bool | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SpeakerReview:
|
||||
speaker_label: str
|
||||
excerpts: tuple[str, ...]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SpeakerMappingReview:
|
||||
speakers: tuple[SpeakerReview, ...]
|
||||
participants: tuple[tuple[str, str], ...]
|
||||
current_mappings: dict[str, str]
|
||||
|
||||
|
||||
def stable_id(value: str) -> str:
|
||||
@@ -84,9 +109,16 @@ def stable_id(value: str) -> str:
|
||||
class MeetingProcessingService:
|
||||
"""Translate UI input into Meeting Lab calls and persisted artifacts."""
|
||||
|
||||
def __init__(self, settings: AppSettings, meeting_lab: MeetingLabPort) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
settings: AppSettings,
|
||||
meeting_lab: MeetingLabPort,
|
||||
glossary: GlossaryRepository | None = None,
|
||||
) -> None:
|
||||
self.settings = settings
|
||||
self.meeting_lab = meeting_lab
|
||||
self.glossary = glossary or GlossaryRepository(settings.glossary_database)
|
||||
self.glossary.initialize()
|
||||
|
||||
def build_context(
|
||||
self,
|
||||
@@ -154,6 +186,7 @@ class MeetingProcessingService:
|
||||
"mentioned_people_are_not_participants": True,
|
||||
},
|
||||
}
|
||||
self._apply_glossary(data)
|
||||
return self.meeting_lab.create_context(data)
|
||||
|
||||
def preserve_upload(self, meeting_id: str, filename: str, source: Any) -> Path:
|
||||
@@ -253,8 +286,164 @@ class MeetingProcessingService:
|
||||
run_dir=result.run_dir,
|
||||
original_protocol=protocol_path.read_text(encoding="utf-8"),
|
||||
protocol_path=protocol_path,
|
||||
speaker_attribution_available=self._speaker_attribution_available(result.run_dir),
|
||||
)
|
||||
|
||||
def load_speaker_mapping_review(
|
||||
self,
|
||||
run_dir: Path,
|
||||
*,
|
||||
excerpts_per_speaker: int = 3,
|
||||
minimum_excerpt_characters: int = 20,
|
||||
) -> SpeakerMappingReview | None:
|
||||
"""Load detected labels and small deterministic identification excerpts."""
|
||||
run_dir = Path(run_dir)
|
||||
transcript_path = run_dir / "diarization" / "transcript_diarized.json"
|
||||
context_path = run_dir / "context" / "meeting_context.yaml"
|
||||
if not transcript_path.is_file() or not context_path.is_file():
|
||||
return None
|
||||
transcript = json.loads(transcript_path.read_text(encoding="utf-8-sig"))
|
||||
context_data = yaml.safe_load(context_path.read_text(encoding="utf-8"))
|
||||
if not isinstance(transcript, dict) or not isinstance(context_data, dict):
|
||||
raise ValueError("Existing run contains malformed speaker review artifacts.")
|
||||
segments = transcript.get("segments")
|
||||
if not isinstance(segments, list):
|
||||
raise ValueError("Diarized transcript has no segments list.")
|
||||
|
||||
texts_by_speaker: dict[str, list[str]] = {}
|
||||
short_by_speaker: dict[str, list[str]] = {}
|
||||
for segment in segments:
|
||||
if not isinstance(segment, dict):
|
||||
continue
|
||||
label = segment.get("speaker_id")
|
||||
text = segment.get("text")
|
||||
if (
|
||||
not isinstance(label, str)
|
||||
or not label.startswith("SPEAKER_")
|
||||
or label == "SPEAKER_UNASSIGNED"
|
||||
or not isinstance(text, str)
|
||||
or not text.strip()
|
||||
):
|
||||
continue
|
||||
normalized = " ".join(text.split())
|
||||
target = (
|
||||
texts_by_speaker
|
||||
if len(normalized) >= minimum_excerpt_characters
|
||||
else short_by_speaker
|
||||
)
|
||||
target.setdefault(label, []).append(normalized)
|
||||
|
||||
labels = sorted(set(texts_by_speaker) | set(short_by_speaker))
|
||||
speakers = []
|
||||
for label in labels:
|
||||
candidates = texts_by_speaker.get(label) or short_by_speaker.get(label, [])
|
||||
speakers.append(SpeakerReview(label, tuple(candidates[:excerpts_per_speaker])))
|
||||
participants = tuple(
|
||||
(participant["participant_id"], participant["display_name"])
|
||||
for participant in context_data.get("participants", [])
|
||||
if isinstance(participant, dict)
|
||||
and isinstance(participant.get("participant_id"), str)
|
||||
and isinstance(participant.get("display_name"), str)
|
||||
)
|
||||
mappings = context_data.get("speaker_mappings")
|
||||
return SpeakerMappingReview(
|
||||
speakers=tuple(speakers),
|
||||
participants=participants,
|
||||
current_mappings=dict(mappings) if isinstance(mappings, dict) else {},
|
||||
)
|
||||
|
||||
def regenerate_protocol(
|
||||
self,
|
||||
run_dir: Path,
|
||||
speaker_mappings: dict[str, str],
|
||||
progress_sink: Callable[[AppProgressEvent], None] | None = None,
|
||||
) -> ProcessingOutcome:
|
||||
"""Persist confirmed mappings and regenerate only the direct protocol."""
|
||||
review = self.load_speaker_mapping_review(run_dir)
|
||||
if review is None:
|
||||
raise ValueError("This run has no diarization artifacts to map.")
|
||||
detected = {speaker.speaker_label for speaker in review.speakers}
|
||||
participant_ids = {participant_id for participant_id, _ in review.participants}
|
||||
unknown_labels = sorted(set(speaker_mappings) - detected)
|
||||
if unknown_labels:
|
||||
raise ValueError(f"Unknown diarization speaker label: {unknown_labels[0]}")
|
||||
unknown_participants = sorted(set(speaker_mappings.values()) - participant_ids)
|
||||
if unknown_participants:
|
||||
raise ValueError(f"Unknown participant ID: {unknown_participants[0]}")
|
||||
assigned_participants = list(speaker_mappings.values())
|
||||
if len(assigned_participants) != len(set(assigned_participants)):
|
||||
raise ValueError("A participant may be assigned to only one speaker label.")
|
||||
|
||||
context_path = Path(run_dir) / "context" / "meeting_context.yaml"
|
||||
context_data = yaml.safe_load(context_path.read_text(encoding="utf-8"))
|
||||
if not isinstance(context_data, dict):
|
||||
raise ValueError("Existing run contains malformed Meeting Context.")
|
||||
context_data["speaker_mappings"] = dict(sorted(speaker_mappings.items()))
|
||||
self._apply_glossary(context_data)
|
||||
context = self.meeting_lab.create_context(context_data)
|
||||
|
||||
def relay(event: Any) -> None:
|
||||
if progress_sink is not None:
|
||||
progress_sink(
|
||||
AppProgressEvent(
|
||||
stage=event.stage,
|
||||
status=event.status,
|
||||
elapsed_seconds=event.elapsed_seconds,
|
||||
progress=event.progress,
|
||||
message=event.message,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.meeting_lab.regenerate_protocol(
|
||||
Path(run_dir),
|
||||
context,
|
||||
relay,
|
||||
model=self.settings.protocol_model,
|
||||
ollama_endpoint=self.settings.ollama_endpoint,
|
||||
protocol_num_ctx=self.settings.protocol_num_ctx,
|
||||
protocol_safe_input_token_budget=(self.settings.protocol_safe_input_token_budget),
|
||||
)
|
||||
protocol_path = Path(result.protocol_path)
|
||||
return ProcessingOutcome(
|
||||
succeeded=True,
|
||||
run_dir=Path(result.run_dir),
|
||||
original_protocol=protocol_path.read_text(encoding="utf-8"),
|
||||
protocol_path=protocol_path,
|
||||
speaker_attribution_available=self._speaker_attribution_available(result.run_dir),
|
||||
)
|
||||
|
||||
def _apply_glossary(self, context_data: dict[str, Any]) -> None:
|
||||
"""Merge active terminology into context without discarding other entities."""
|
||||
glossary_terms = render_glossary_terms(self.glossary.list(active_only=True))
|
||||
known_entities = context_data.setdefault("known_entities", {})
|
||||
if glossary_terms:
|
||||
known_entities["Authoritative terminology"] = glossary_terms
|
||||
else:
|
||||
known_entities.pop("Authoritative terminology", None)
|
||||
rules = context_data.setdefault("context_rules", {})
|
||||
rules["glossary_canonical_spelling"] = (
|
||||
"Use canonical glossary spellings only when the meeting clearly refers to "
|
||||
"those terms; do not invent matches or replace unrelated words."
|
||||
)
|
||||
rules["glossary_core_terms"] = (
|
||||
"Preserve surrounding context and use canonical core terms inside compounds "
|
||||
"where appropriate."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _speaker_attribution_available(run_dir: Path | None) -> bool | None:
|
||||
if run_dir is None:
|
||||
return None
|
||||
metadata_path = Path(run_dir) / "protocol" / "runtime_metadata.json"
|
||||
if not metadata_path.is_file():
|
||||
return None
|
||||
try:
|
||||
metadata = json.loads(metadata_path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError):
|
||||
return None
|
||||
value = metadata.get("speaker_attribution_available")
|
||||
return value if isinstance(value, bool) else None
|
||||
|
||||
@staticmethod
|
||||
def _read_failure(run_dir: Path | None) -> dict[str, str]:
|
||||
if run_dir is None:
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
"""Versioned JSON import/export for the user-facing run input form."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from mka.application.meeting_service import ParticipantInput, stable_id
|
||||
from mka.application.people_yaml import ATTENDANCE_VALUES, PARTICIPANT_ID_PATTERN
|
||||
|
||||
RUN_INPUT_SCHEMA_VERSION = 1
|
||||
SUPPORTED_LANGUAGES = frozenset({"de", "en"})
|
||||
|
||||
|
||||
class RunInputJsonError(ValueError):
|
||||
"""Raised when a run-input JSON document is malformed or unsupported."""
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RunInputState:
|
||||
"""All user-configurable values needed before starting a processing run."""
|
||||
|
||||
title: str
|
||||
description: str
|
||||
language: str
|
||||
meeting_date: date | None
|
||||
participants: tuple[ParticipantInput, ...]
|
||||
audio_normalization: bool
|
||||
diarization_enabled: bool
|
||||
source_file_name: str | None = None
|
||||
|
||||
@classmethod
|
||||
def defaults(cls) -> RunInputState:
|
||||
return cls(
|
||||
title="",
|
||||
description="",
|
||||
language="de",
|
||||
meeting_date=date.today(),
|
||||
participants=(ParticipantInput(participant_id="", display_name=""),),
|
||||
audio_normalization=True,
|
||||
diarization_enabled=False,
|
||||
)
|
||||
|
||||
|
||||
def export_run_inputs(state: RunInputState) -> str:
|
||||
"""Serialize form state as deterministic, human-readable JSON."""
|
||||
source_file_name = _source_file_name(state.source_file_name)
|
||||
document = {
|
||||
"schema_version": RUN_INPUT_SCHEMA_VERSION,
|
||||
"meeting": {
|
||||
"title": state.title,
|
||||
"description": state.description,
|
||||
"language": state.language,
|
||||
"date": state.meeting_date.isoformat() if state.meeting_date else None,
|
||||
"participants": [
|
||||
{
|
||||
"participant_id": person.participant_id,
|
||||
"display_name": person.display_name,
|
||||
"role": person.role,
|
||||
"organization": person.organization,
|
||||
"attendance_status": person.attendance_status,
|
||||
}
|
||||
for person in state.participants
|
||||
],
|
||||
},
|
||||
"processing": {
|
||||
"audio_normalization": state.audio_normalization,
|
||||
"diarization_enabled": state.diarization_enabled,
|
||||
},
|
||||
"source_file_name": source_file_name,
|
||||
}
|
||||
return json.dumps(document, ensure_ascii=False, indent=2) + "\n"
|
||||
|
||||
|
||||
def import_run_inputs(content: str | bytes) -> RunInputState:
|
||||
"""Parse supported fields, applying current defaults to omitted optional fields."""
|
||||
try:
|
||||
if isinstance(content, bytes):
|
||||
content = content.decode("utf-8")
|
||||
document = json.loads(content)
|
||||
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
||||
raise RunInputJsonError(f"Malformed input JSON: {exc}") from exc
|
||||
if not isinstance(document, dict):
|
||||
raise RunInputJsonError("Input JSON must contain a top-level object.")
|
||||
version = document.get("schema_version")
|
||||
if type(version) is not int or version != RUN_INPUT_SCHEMA_VERSION:
|
||||
raise RunInputJsonError(
|
||||
f"Unsupported input schema_version {version!r}; expected {RUN_INPUT_SCHEMA_VERSION}."
|
||||
)
|
||||
|
||||
defaults = RunInputState.defaults()
|
||||
meeting = _optional_mapping(document, "meeting")
|
||||
processing = _optional_mapping(document, "processing")
|
||||
title = _optional_text(meeting, "title", defaults.title)
|
||||
description = _optional_text(meeting, "description", defaults.description)
|
||||
language = _optional_text(meeting, "language", defaults.language)
|
||||
if language not in SUPPORTED_LANGUAGES:
|
||||
raise RunInputJsonError(f"Unsupported meeting language: {language!r}.")
|
||||
meeting_date = _meeting_date(meeting, defaults.meeting_date)
|
||||
participants = _participants(meeting, defaults.participants)
|
||||
audio_normalization = _optional_bool(
|
||||
processing, "audio_normalization", defaults.audio_normalization
|
||||
)
|
||||
diarization_enabled = _optional_bool(
|
||||
processing, "diarization_enabled", defaults.diarization_enabled
|
||||
)
|
||||
source_file_name = _source_file_name(document.get("source_file_name"))
|
||||
return RunInputState(
|
||||
title=title,
|
||||
description=description,
|
||||
language=language,
|
||||
meeting_date=meeting_date,
|
||||
participants=participants,
|
||||
audio_normalization=audio_normalization,
|
||||
diarization_enabled=diarization_enabled,
|
||||
source_file_name=source_file_name,
|
||||
)
|
||||
|
||||
|
||||
def run_input_filename(title: str) -> str:
|
||||
"""Build a stable download filename without filesystem-specific characters."""
|
||||
suffix = stable_id(title) if title.strip() else "untitled"
|
||||
return f"meeting-inputs-{suffix}.json"
|
||||
|
||||
|
||||
def _optional_mapping(document: dict[str, Any], field: str) -> dict[str, Any]:
|
||||
value = document.get(field, {})
|
||||
if not isinstance(value, dict):
|
||||
raise RunInputJsonError(f"Field {field!r} must be an object.")
|
||||
return value
|
||||
|
||||
|
||||
def _optional_text(document: dict[str, Any], field: str, default: str) -> str:
|
||||
value = document.get(field, default)
|
||||
if not isinstance(value, str):
|
||||
raise RunInputJsonError(f"Field {field!r} must be text.")
|
||||
return value
|
||||
|
||||
|
||||
def _optional_bool(document: dict[str, Any], field: str, default: bool) -> bool:
|
||||
value = document.get(field, default)
|
||||
if type(value) is not bool:
|
||||
raise RunInputJsonError(f"Field {field!r} must be true or false.")
|
||||
return value
|
||||
|
||||
|
||||
def _meeting_date(document: dict[str, Any], default: date | None) -> date | None:
|
||||
if "date" not in document:
|
||||
return default
|
||||
value = document["date"]
|
||||
if value is None:
|
||||
return None
|
||||
if not isinstance(value, str):
|
||||
raise RunInputJsonError("Field 'date' must be an ISO date or null.")
|
||||
try:
|
||||
return date.fromisoformat(value)
|
||||
except ValueError as exc:
|
||||
raise RunInputJsonError("Field 'date' must be a valid ISO date or null.") from exc
|
||||
|
||||
|
||||
def _participants(
|
||||
document: dict[str, Any], default: Sequence[ParticipantInput]
|
||||
) -> tuple[ParticipantInput, ...]:
|
||||
if "participants" not in document:
|
||||
return tuple(default)
|
||||
entries = document["participants"]
|
||||
if not isinstance(entries, list):
|
||||
raise RunInputJsonError("Field 'participants' must be a list.")
|
||||
people: list[ParticipantInput] = []
|
||||
seen_ids: set[str] = set()
|
||||
for index, entry in enumerate(entries, start=1):
|
||||
if not isinstance(entry, dict):
|
||||
raise RunInputJsonError(f"Participant {index} must be an object.")
|
||||
participant_id = _optional_text(entry, "participant_id", "")
|
||||
display_name = _optional_text(entry, "display_name", "")
|
||||
role = _optional_text(entry, "role", "")
|
||||
organization = _optional_text(entry, "organization", "")
|
||||
attendance = _optional_text(entry, "attendance_status", "present")
|
||||
if bool(participant_id) != bool(display_name):
|
||||
raise RunInputJsonError(
|
||||
f"Participant {index} must provide both participant_id and display_name."
|
||||
)
|
||||
if participant_id and PARTICIPANT_ID_PATTERN.fullmatch(participant_id) is None:
|
||||
raise RunInputJsonError(
|
||||
f"Participant {index} has invalid participant_id {participant_id!r}."
|
||||
)
|
||||
if participant_id in seen_ids:
|
||||
raise RunInputJsonError(f"Duplicate participant_id: {participant_id!r}.")
|
||||
if participant_id:
|
||||
seen_ids.add(participant_id)
|
||||
if attendance not in ATTENDANCE_VALUES:
|
||||
raise RunInputJsonError(
|
||||
f"Participant {index} has invalid attendance_status {attendance!r}."
|
||||
)
|
||||
people.append(
|
||||
ParticipantInput(
|
||||
participant_id=participant_id,
|
||||
display_name=display_name,
|
||||
role=role,
|
||||
organization=organization,
|
||||
attendance_status=attendance,
|
||||
)
|
||||
)
|
||||
return tuple(people)
|
||||
|
||||
|
||||
def _source_file_name(value: Any) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
if not isinstance(value, str) or not value.strip():
|
||||
raise RunInputJsonError("Field 'source_file_name' must be non-empty text or null.")
|
||||
if Path(value).name != value:
|
||||
raise RunInputJsonError("Field 'source_file_name' must be a filename, not a path.")
|
||||
return value
|
||||
@@ -18,6 +18,7 @@ class MeetingLabGateway:
|
||||
from src.meeting_lab.models.meeting_context import create_meeting_context
|
||||
from src.meeting_lab.orchestration.mvp import (
|
||||
MvpMeetingConfig,
|
||||
regenerate_mvp_protocol,
|
||||
run_mvp_meeting,
|
||||
)
|
||||
except ImportError as exc:
|
||||
@@ -28,6 +29,7 @@ class MeetingLabGateway:
|
||||
self._config_type = MvpMeetingConfig
|
||||
self._create_context = create_meeting_context
|
||||
self._run_mvp_meeting = run_mvp_meeting
|
||||
self._regenerate_mvp_protocol = regenerate_mvp_protocol
|
||||
|
||||
def create_context(self, data: dict[str, Any]) -> Any:
|
||||
"""Validate structured context through Meeting Lab's domain boundary."""
|
||||
@@ -49,3 +51,18 @@ class MeetingLabGateway:
|
||||
meeting_context=meeting_context,
|
||||
progress_sink=progress_sink,
|
||||
)
|
||||
|
||||
def regenerate_protocol(
|
||||
self,
|
||||
run_dir: Any,
|
||||
meeting_context: Any,
|
||||
progress_sink: Callable[[Any], None],
|
||||
**options: Any,
|
||||
) -> Any:
|
||||
"""Regenerate protocol artifacts without rerunning media processing."""
|
||||
return self._regenerate_mvp_protocol(
|
||||
run_dir,
|
||||
meeting_context=meeting_context,
|
||||
progress_sink=progress_sink,
|
||||
**options,
|
||||
)
|
||||
|
||||
+268
-8
@@ -9,6 +9,11 @@ from uuid import uuid4
|
||||
import streamlit as st
|
||||
|
||||
from mka.application.config import AppSettings, ConfigurationError
|
||||
from mka.application.glossary import (
|
||||
GLOSSARY_CATEGORIES,
|
||||
GlossaryConflictError,
|
||||
GlossaryRepository,
|
||||
)
|
||||
from mka.application.meeting_service import (
|
||||
STAGES,
|
||||
AppProgressEvent,
|
||||
@@ -23,6 +28,13 @@ from mka.application.people_yaml import (
|
||||
export_people_yaml,
|
||||
import_people_yaml,
|
||||
)
|
||||
from mka.application.run_inputs import (
|
||||
RunInputJsonError,
|
||||
RunInputState,
|
||||
export_run_inputs,
|
||||
import_run_inputs,
|
||||
run_input_filename,
|
||||
)
|
||||
from mka.integrations.meeting_lab import (
|
||||
MeetingLabGateway,
|
||||
MeetingLabUnavailableError,
|
||||
@@ -36,6 +48,87 @@ STAGE_LABELS = {
|
||||
}
|
||||
|
||||
|
||||
def _parse_aliases(value: str) -> tuple[str, ...]:
|
||||
"""Parse one alias per line while tolerating comma-separated input."""
|
||||
return tuple(
|
||||
alias.strip() for line in value.splitlines() for alias in line.split(",") if alias.strip()
|
||||
)
|
||||
|
||||
|
||||
def _render_glossary(repository: GlossaryRepository) -> None:
|
||||
"""Render simple global glossary CRUD controls."""
|
||||
with st.expander("Terminology glossary", expanded=False):
|
||||
st.caption(
|
||||
"Store canonical core terms and recognition aliases. Compound phrases are "
|
||||
"composed from meeting context during protocol generation."
|
||||
)
|
||||
with st.form("glossary_add"):
|
||||
columns = st.columns(2)
|
||||
canonical = columns[0].text_input("Canonical term")
|
||||
category = columns[1].selectbox("Category", GLOSSARY_CATEGORIES)
|
||||
aliases = st.text_area("Aliases", help="One per line or comma-separated.")
|
||||
description = st.text_area("Optional description")
|
||||
if st.form_submit_button("Add glossary entry"):
|
||||
try:
|
||||
repository.create(
|
||||
canonical,
|
||||
category,
|
||||
aliases=_parse_aliases(aliases),
|
||||
description=description,
|
||||
)
|
||||
except (GlossaryConflictError, ValueError) as exc:
|
||||
st.error(str(exc))
|
||||
else:
|
||||
st.success("Glossary entry added.")
|
||||
st.rerun()
|
||||
|
||||
search = st.text_input("Search glossary")
|
||||
active_only = st.checkbox("Show active entries only")
|
||||
entries = repository.list(search, active_only=active_only)
|
||||
st.caption(f"{len(entries)} glossary entries")
|
||||
for entry in entries:
|
||||
status = "active" if entry.is_active else "inactive"
|
||||
with (
|
||||
st.expander(f"{entry.canonical_term} · {entry.category} · {status}"),
|
||||
st.form(f"glossary_edit_{entry.id}"),
|
||||
):
|
||||
columns = st.columns(2)
|
||||
edited_canonical = columns[0].text_input("Canonical term", entry.canonical_term)
|
||||
edited_category = columns[1].selectbox(
|
||||
"Category",
|
||||
GLOSSARY_CATEGORIES,
|
||||
index=GLOSSARY_CATEGORIES.index(entry.category),
|
||||
)
|
||||
edited_aliases = st.text_area("Aliases", "\n".join(entry.aliases))
|
||||
edited_description = st.text_area("Optional description", entry.description or "")
|
||||
edited_active = st.checkbox("Active", value=entry.is_active)
|
||||
delete_confirmed = st.checkbox(
|
||||
"Permanently delete this entry",
|
||||
help="Prefer clearing Active for normal use.",
|
||||
)
|
||||
action_columns = st.columns(2)
|
||||
save = action_columns[0].form_submit_button("Save changes")
|
||||
delete = action_columns[1].form_submit_button(
|
||||
"Delete", disabled=not delete_confirmed
|
||||
)
|
||||
try:
|
||||
if save:
|
||||
repository.update(
|
||||
entry.id,
|
||||
edited_canonical,
|
||||
edited_category,
|
||||
aliases=_parse_aliases(edited_aliases),
|
||||
description=edited_description,
|
||||
is_active=edited_active,
|
||||
)
|
||||
st.rerun()
|
||||
if delete:
|
||||
repository.delete(entry.id)
|
||||
st.rerun()
|
||||
except (GlossaryConflictError, ValueError) as exc:
|
||||
st.error(str(exc))
|
||||
|
||||
|
||||
def _new_participant() -> dict[str, str]:
|
||||
return {
|
||||
"row_id": uuid4().hex,
|
||||
@@ -51,6 +144,51 @@ def _initialize_state() -> None:
|
||||
st.session_state.setdefault("participants", [_new_participant()])
|
||||
st.session_state.setdefault("outcome", None)
|
||||
st.session_state.setdefault("edited_protocol", "")
|
||||
st.session_state.setdefault("source_media_widget_generation", 0)
|
||||
_apply_pending_run_inputs()
|
||||
_apply_pending_edited_protocol()
|
||||
|
||||
|
||||
def _queue_run_inputs(value: RunInputState) -> None:
|
||||
"""Defer form restoration until the beginning of the next Streamlit run."""
|
||||
st.session_state["pending_run_inputs"] = value
|
||||
|
||||
|
||||
def _apply_pending_run_inputs() -> None:
|
||||
"""Restore imported values before any corresponding widget is instantiated."""
|
||||
value = st.session_state.pop("pending_run_inputs", None)
|
||||
if value is None:
|
||||
return
|
||||
st.session_state.update(
|
||||
{
|
||||
"meeting_title": value.title,
|
||||
"meeting_description": value.description,
|
||||
"meeting_language": value.language,
|
||||
"meeting_has_date": value.meeting_date is not None,
|
||||
"meeting_date": value.meeting_date or date.today(),
|
||||
"participants": _people_to_rows(list(value.participants)),
|
||||
"audio_normalization": value.audio_normalization,
|
||||
"diarization_enabled": value.diarization_enabled,
|
||||
"imported_source_file_name": value.source_file_name,
|
||||
"run_input_import_message": (
|
||||
"Meeting inputs imported. Select the source media before processing."
|
||||
),
|
||||
"source_media_widget_generation": (
|
||||
st.session_state.get("source_media_widget_generation", 0) + 1
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _apply_pending_edited_protocol() -> None:
|
||||
"""Apply a deferred widget value before the widget is instantiated."""
|
||||
if "pending_edited_protocol" in st.session_state:
|
||||
st.session_state["edited_protocol"] = st.session_state.pop("pending_edited_protocol")
|
||||
|
||||
|
||||
def _queue_edited_protocol(value: str) -> None:
|
||||
"""Defer an edited-protocol widget update until the next Streamlit run."""
|
||||
st.session_state["pending_edited_protocol"] = value
|
||||
|
||||
|
||||
def _people_to_rows(people: list[ParticipantInput]) -> list[dict[str, str]]:
|
||||
@@ -68,6 +206,27 @@ def _people_to_rows(people: list[ParticipantInput]) -> list[dict[str, str]]:
|
||||
]
|
||||
|
||||
|
||||
def _render_run_input_import() -> None:
|
||||
"""Render import controls before the widgets whose state they restore."""
|
||||
st.subheader("Input configuration")
|
||||
imported_file = st.file_uploader(
|
||||
"Import inputs",
|
||||
type=["json"],
|
||||
key="run_input_import_file",
|
||||
help="Restore form values only; source media is never included.",
|
||||
)
|
||||
if st.button("Import input configuration", disabled=imported_file is None):
|
||||
try:
|
||||
imported = import_run_inputs(imported_file.getvalue())
|
||||
except RunInputJsonError as exc:
|
||||
st.error(str(exc))
|
||||
else:
|
||||
_queue_run_inputs(imported)
|
||||
st.rerun()
|
||||
if message := st.session_state.pop("run_input_import_message", None):
|
||||
st.success(message)
|
||||
|
||||
|
||||
def _render_participants() -> list[ParticipantInput]:
|
||||
st.subheader("People")
|
||||
st.caption("Record whether each relevant person attended or was only mentioned.")
|
||||
@@ -196,6 +355,13 @@ def _render_result() -> None:
|
||||
|
||||
st.success("Processing completed. Review the generated protocol before use.")
|
||||
st.caption(f"Run artifacts: {outcome.run_dir}")
|
||||
if outcome.speaker_attribution_available is False:
|
||||
st.warning(
|
||||
"Speaker attribution was unavailable for this protocol because the "
|
||||
"safe-budget fallback removed diarization labels from the prompt."
|
||||
)
|
||||
if message := st.session_state.pop("speaker_mapping_message", None):
|
||||
st.success(message)
|
||||
with st.expander("Original generated protocol", expanded=False):
|
||||
st.markdown(outcome.original_protocol or "")
|
||||
edited = st.text_area(
|
||||
@@ -208,6 +374,60 @@ def _render_result() -> None:
|
||||
path = MeetingProcessingService.save_edited_protocol(outcome.run_dir, edited)
|
||||
st.success(f"Saved edited protocol to {path}")
|
||||
|
||||
try:
|
||||
service = MeetingProcessingService(AppSettings.from_environment(), MeetingLabGateway())
|
||||
review = service.load_speaker_mapping_review(outcome.run_dir)
|
||||
except (MeetingLabUnavailableError, OSError, ValueError) as exc:
|
||||
st.warning(f"Speaker mapping is unavailable: {exc}")
|
||||
return
|
||||
if review is None or not review.speakers:
|
||||
return
|
||||
|
||||
st.subheader("Identify diarized speakers")
|
||||
st.caption(
|
||||
"Confirm identities explicitly. Unmapped speakers remain anonymous; "
|
||||
"the diarized source transcript is not modified."
|
||||
)
|
||||
participant_names = dict(review.participants)
|
||||
options = [None, *participant_names]
|
||||
selections: dict[str, str] = {}
|
||||
for speaker in review.speakers:
|
||||
current = review.current_mappings.get(speaker.speaker_label)
|
||||
selected = st.selectbox(
|
||||
speaker.speaker_label,
|
||||
options=options,
|
||||
index=options.index(current) if current in options else 0,
|
||||
format_func=lambda value, names=participant_names: (
|
||||
"Unmapped / Unknown" if value is None else names[value]
|
||||
),
|
||||
key=f"speaker_mapping_{outcome.run_dir.name}_{speaker.speaker_label}",
|
||||
)
|
||||
if selected is not None:
|
||||
selections[speaker.speaker_label] = selected
|
||||
for excerpt in speaker.excerpts:
|
||||
st.caption(f"“{excerpt}”")
|
||||
|
||||
duplicate_assignments = len(selections.values()) != len(set(selections.values()))
|
||||
if duplicate_assignments:
|
||||
st.error("Each participant can be assigned to only one detected speaker.")
|
||||
if st.button(
|
||||
"Regenerate protocol with confirmed speakers",
|
||||
disabled=duplicate_assignments,
|
||||
type="primary",
|
||||
):
|
||||
try:
|
||||
with st.spinner("Regenerating protocol without rerunning audio processing..."):
|
||||
regenerated = service.regenerate_protocol(outcome.run_dir, selections)
|
||||
except (OSError, RuntimeError, ValueError) as exc:
|
||||
st.error(f"Protocol regeneration failed: {exc}")
|
||||
else:
|
||||
st.session_state.outcome = regenerated
|
||||
_queue_edited_protocol(regenerated.original_protocol or "")
|
||||
st.session_state.speaker_mapping_message = (
|
||||
"Speaker mappings saved and protocol regenerated."
|
||||
)
|
||||
st.rerun()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
st.set_page_config(page_title="Meeting Assistant", layout="wide")
|
||||
@@ -215,15 +435,36 @@ def main() -> None:
|
||||
st.title("Meeting Assistant")
|
||||
st.caption("Create meeting context, run Meeting Lab, and review the protocol.")
|
||||
|
||||
settings = AppSettings.from_environment()
|
||||
glossary = GlossaryRepository(settings.glossary_database)
|
||||
glossary.initialize()
|
||||
_render_glossary(glossary)
|
||||
|
||||
_render_run_input_import()
|
||||
|
||||
st.header("Meeting and audio")
|
||||
audio = st.file_uploader("Audio recording", type=["wav", "flac", "m4a"])
|
||||
title = st.text_input("Meeting title")
|
||||
description = st.text_area("Description / context", height=100)
|
||||
audio = st.file_uploader(
|
||||
"Audio recording",
|
||||
type=["wav", "flac", "m4a"],
|
||||
key=f"source_media_{st.session_state.source_media_widget_generation}",
|
||||
)
|
||||
imported_source_name = st.session_state.get("imported_source_file_name")
|
||||
if audio is None and imported_source_name:
|
||||
st.caption(
|
||||
f"Previous source filename: {imported_source_name}. "
|
||||
"Select the media file again before processing."
|
||||
)
|
||||
title = st.text_input("Meeting title", key="meeting_title")
|
||||
description = st.text_area("Description / context", height=100, key="meeting_description")
|
||||
metadata_columns = st.columns(3)
|
||||
language = metadata_columns[0].selectbox("Meeting language", options=["de", "en"])
|
||||
has_date = metadata_columns[1].checkbox("Meeting date is known", value=True)
|
||||
language = metadata_columns[0].selectbox(
|
||||
"Meeting language", options=["de", "en"], key="meeting_language"
|
||||
)
|
||||
has_date = metadata_columns[1].checkbox(
|
||||
"Meeting date is known", value=True, key="meeting_has_date"
|
||||
)
|
||||
selected_date: date | None = (
|
||||
metadata_columns[2].date_input("Meeting date") if has_date else None
|
||||
metadata_columns[2].date_input("Meeting date", key="meeting_date") if has_date else None
|
||||
)
|
||||
|
||||
participants = _render_participants()
|
||||
@@ -232,6 +473,7 @@ def main() -> None:
|
||||
audio_normalization = st.checkbox(
|
||||
"Audio normalization",
|
||||
value=True,
|
||||
key="audio_normalization",
|
||||
help=(
|
||||
"Normalize speech loudness during preparation. WAV, FLAC, and M4A "
|
||||
"are always converted to the canonical Meeting Lab audio format, "
|
||||
@@ -240,9 +482,28 @@ def main() -> None:
|
||||
)
|
||||
diarization_enabled = st.checkbox(
|
||||
"Enable speaker diarization",
|
||||
key="diarization_enabled",
|
||||
help="Speaker labels remain anonymous; identities are never inferred.",
|
||||
)
|
||||
|
||||
current_inputs = RunInputState(
|
||||
title=title,
|
||||
description=description,
|
||||
language=language,
|
||||
meeting_date=selected_date,
|
||||
participants=tuple(participants),
|
||||
audio_normalization=audio_normalization,
|
||||
diarization_enabled=diarization_enabled,
|
||||
source_file_name=(audio.name if audio is not None else imported_source_name),
|
||||
)
|
||||
st.download_button(
|
||||
"Export inputs",
|
||||
data=export_run_inputs(current_inputs).encode("utf-8"),
|
||||
file_name=run_input_filename(title),
|
||||
mime="application/json",
|
||||
help="Download the current form configuration without source media or run results.",
|
||||
)
|
||||
|
||||
if st.button("Start processing", type="primary", disabled=audio is None):
|
||||
if not title.strip():
|
||||
st.error("Meeting title is required.")
|
||||
@@ -252,9 +513,8 @@ def main() -> None:
|
||||
):
|
||||
st.error("Every person row needs a name and participant ID.")
|
||||
else:
|
||||
settings = AppSettings.from_environment()
|
||||
try:
|
||||
service = MeetingProcessingService(settings, MeetingLabGateway())
|
||||
service = MeetingProcessingService(settings, MeetingLabGateway(), glossary)
|
||||
meeting = MeetingDetails(
|
||||
title=title,
|
||||
language=language,
|
||||
|
||||
Reference in New Issue
Block a user