<jupyter_start><jupyter_text><jupyter_code>!pip install pyvirtualdisplay
!apt-get install -y ffmpeg xvfb python-opengl
!apt-get update
!apt-get install cmake
!pip install --upgrade setuptools
!pip install ez_setup
!pip install gym[atari]
import gym
from gym import logger as logstat
logstat.set_level(gym.logger.INFO)
import tensorflow
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
from gym.wrappers import Monitor
import math
import glob
import io
import base64
from IPython.display import HTML

from IPython import display as ipythondisplay
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1400,900))
display.start()
def videoPlayer():
  mp4s = glob.glob('video/*mp4')
  if len(mp4s) > 0:
    mp4 = mp4s[0]
    video = io.open(mp4, 'r+b').read()
    encoded = base64.b64encode(video)
    ipythondisplay.display(
        HTML(data='''<video alt="video" autoplay 
                loop controls style="height: 500px;">
                <source src="data:video/mp4;base64,{0}" type="video/mp4" />
             </video>'''.format(encoded.decode('ascii'))))
  else:
    print("Could not find the Video File")

def wrap_env(env):
  env = Monitor(env, './video', force=True)
  return env
if __name__ == "__main__":
  env = wrap_env(gym.make("CartPole-v0"))
  total_reward = 0.0
  total_steps = 0
  obs = env.reset()

  while True:
    action = env.action_space.sample()
    obs, reward, is_done, info = env.step(action)
    total_reward += reward;
    total_steps += 1;
    if is_done:
      break;
  print("Epidose done in %d steps, with the random reward accumulating to: %d" % (total_steps, total_reward))

  env.close()
  videoPlayer()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12002341920374707, 'fraction_numerical': 0.020491803278688523, 'mean_word_length': 3.9825072886297375, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 9, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '338676', 'license': 'MIT', 'n_tokens_mistral': 612, 'n_tokens_neox': 585, 'n_words': 159, 'path': 'Reinforcement_Learning_With_Swastik_Episode_1.ipynb', 'repo_name': 'swastiknath/Reinforcement_Learning_With_Swastik', 'size': '1708'}