from fractions import Fraction import io import json from PIL import Image from .bootstrap import production as a def instruction_suffix(instruction): value = instruction.strip() if not value: return '' if len(value) > 2000: raise ValueError('Keep the optional task instruction below 2000 characters.') return '\n' + json.dumps({'episode_instruction': value}, ensure_ascii=False, sort_keys=True, separators=(',', ':'), allow_nan=False) def human_transport(frames): from flora_runtime.exact_frame_serving import encode_regularized_image output = {} for index, image in frames.items(): payload = encode_regularized_image(image, encoding='jpeg_q98_444')['payload'] with Image.open(io.BytesIO(payload)) as decoded: output[index] = decoded.convert('RGB') return output def temporal_inputs(frames, window, pool, proc, roles, instruction=''): from transformers.video_utils import VideoMetadata from flora_runtime.exact_frame_serving import regularized_resize_dims profile = window.window_profile if len(frames) != profile.slot_count: raise ValueError('Incorrect native temporal slot count') regularized = [] for image in frames: image = image.convert('RGB') height, width = regularized_resize_dims(height=image.height, width=image.width, min_pixels=256, max_pixels=40000 if len(roles) == 1 else 160000) if image.size != (width, height): image = image.resize((width, height), Image.Resampling.BICUBIC) regularized.append(image) prompt = a.temporal_prompt(window, pool) + instruction_suffix(instruction) text = proc.apply_chat_template([dict(role='user', content=prompt.replace('