Spaces:
Sleeping
Sleeping
File size: 606 Bytes
f432fa9 758613a f432fa9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import regex as re
SPEAKER_LINE = re.compile(r"^(Speaker\s+\d+):\s")
def validate_output(text: str, min_lines: int = 2, max_speaker_index: int = 9) -> bool:
if not text:
return False
lines = [ln for ln in text.splitlines() if ln.strip()]
if len(lines) < min_lines:
return False
if not all(SPEAKER_LINE.match(ln) for ln in lines):
return False
for ln in lines:
try:
num = int(ln.split(":")[0].split()[1])
if num > max_speaker_index:
return False
except Exception:
return False
return True
|