Spaces:
Sleeping

File size: 2,515 Bytes
45d1541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Versioned text-only visual elicitation metadata. Never accepts an image upload."""
VISION_METADATA_KEYS = frozenset({
    'vision_protocol_version', 'vision_image_origin', 'vision_image_transmitted',
    'vision_transcript_confirmed', 'vision_meaning_equivalence',
    'vision_final_confirmed', 'vision_paraphrase_edited',
})


def validate_vision_review(record):
    metadata = record.metadata
    if not any(key in metadata for key in VISION_METADATA_KEYS):
        return record  # Historical records retain their original contract.
    if metadata.get('vision_protocol_version') != 'local-image-meaning-v1':
        raise ValueError('Unsupported Vision Quest protocol')
    if record.game_id != 'vision_quest' or record.input_modality not in {'text', 'speech'}:
        raise ValueError('Vision Quest collects speech/text, not image or multimodal payloads')
    origin = metadata.get('vision_image_origin')
    if origin not in {'provided', 'device', 'camera'}:
        raise ValueError('Invalid visual stimulus origin')
    expected_asset = 'vision-original-market-v1' if origin == 'provided' else ''
    if (record.image_asset_id or '') != expected_asset:
        raise ValueError('Device image references must not leave the device')
    if metadata.get('vision_image_transmitted') is not False:
        raise ValueError('Images are not transmitted under this protocol')
    if metadata.get('vision_transcript_confirmed') is not True or metadata.get('vision_final_confirmed') is not True:
        raise ValueError('Separate transcript and meaning confirmations are required')
    if not (record.source_text or '').strip() or record.source_text != record.user_transcript_final:
        raise ValueError('The submitted source must be the user-confirmed transcript')
    initial, final = (record.machine_output_initial or '').strip(), (record.user_output_final or '').strip()
    if not initial or not final:
        raise ValueError('Keep the AI paraphrase and user-final wording separately')
    judgment = metadata.get('vision_meaning_equivalence')
    if judgment not in {'same', 'partly', 'different'}:
        raise ValueError('A speaker meaning-equivalence judgment is required')
    if judgment != 'same' and initial == final:
        raise ValueError('Correct a partly/differently understood paraphrase before contributing')
    if metadata.get('vision_paraphrase_edited') is not (initial != final):
        raise ValueError('Paraphrase edit flag does not match the recorded pair')
    return record