<commit_before>from gym import wrappers
from gym.monitoring import video_recorder
import subprocess
from gym import error
import logging

logger = logging.getLogger(__name__)


class UniMonitor(wrappers.Monitor):
    def __init__(self, env, directory, video_callable=None, force=False, resume=False,
                 write_upon_reset=False, uid=None, mode=None):
        super(UniMonitor, self).__init__(
            env,
            directory,
            video_callable=video_callable,
            force=force, resume=resume,
            write_upon_reset=write_upon_reset,
            uid=uid,
            mode=mode
        )

    def _reset_video_recorder(self):
        # Close any existing video recorder
        if self.video_recorder:
            self._close_video_recorder()

        # Start recording the next video.
        self.video_recorder = UniStreamRecorder(
            env=self.env,
            metadata={'episode_id': self.episode_id},
            enabled=self._video_enabled(),
        )
        self.video_recorder.capture_frame()


class UniStreamRecorder(video_recorder.VideoRecorder):
    def __init__(self, env, path=None, metadata=None, enabled=True, base_path=None):
        super(UniStreamRecorder, self).__init__(env, path=path, metadata=metadata, enabled=enabled, base_path=base_path)

    def _encode_image_frame(self, frame):
        if not self.encoder:
            self.encoder = UniImageEncoder(self.path, frame.shape, self.frames_per_sec)<commit_msg>add base_path to video recorder<commit_after>import logging
import os
import subprocess

from gym import error
from gym import wrappers
from gym.monitoring import video_recorder

logger = logging.getLogger(__name__)


class UniMonitor(wrappers.Monitor):
    def __init__(self, env, directory, video_callable=None, force=False, resume=False,
                 write_upon_reset=False, uid=None, mode=None):
        super(UniMonitor, self).__init__(
            env,
            directory,
            video_callable=video_callable,
            force=force, resume=resume,
            write_upon_reset=write_upon_reset,
            uid=uid,
            mode=mode
        )

    def _reset_video_recorder(self):
        # Close any existing video recorder
        if self.video_recorder:
            self._close_video_recorder()

        # Start recording the next video.
        self.video_recorder = UniStreamRecorder(
            env=self.env,
            base_path=os.path.join(self.directory, '{}.video.{}.video{:06}'.format(self.file_prefix, self.file_infix, self.episode_id)),
            metadata={'episode_id': self.episode_id},
            enabled=self._video_enabled(),
        )
        self.video_recorder.capture_frame()


class UniStreamRecorder(video_recorder.VideoRecorder):
    def __init__(self, env, path=None, metadata=None, enabled=True, base_path=None):
        super(UniStreamRecorder, self).__init__(env, path=path, metadata=metadata, enabled=enabled, base_path=base_path)

    def _encode_image_frame(self, frame):
        if not self.encoder:
            self.encoder = UniImageEncoder(self.path, frame.shape, self.frames_per_sec)
{'fraction_non_alphanumeric': 0.09050350541746335, 'fraction_numerical': 0.0006373486297004461, 'mean_word_length': 2.973417721518987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2795783', 'n_tokens_mistral': 932, 'n_tokens_neox': 903, 'n_words': 183}