|
|
import streamlit as st |
|
|
import gym |
|
|
import gym_super_mario_bros |
|
|
import numpy as np |
|
|
import cv2 |
|
|
from PIL import Image |
|
|
|
|
|
|
|
|
env = gym.make('SuperMarioBros-v0') |
|
|
env.reset() |
|
|
|
|
|
|
|
|
st.title("Super Mario Bros. Game!") |
|
|
st.write("Use the arrow keys to control Mario!") |
|
|
action = st.slider("Move Mario", 0, 3, 1, step=1) |
|
|
|
|
|
|
|
|
def convert_frame_to_image(frame): |
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
return Image.fromarray(frame) |
|
|
|
|
|
|
|
|
if st.button("Start Game"): |
|
|
st.write("Game is running. Use the slider to control Mario.") |
|
|
|
|
|
while True: |
|
|
|
|
|
action_taken = np.array([action]) |
|
|
state, reward, done, info = env.step(action_taken) |
|
|
|
|
|
|
|
|
frame = convert_frame_to_image(state) |
|
|
st.image(frame, use_column_width=True) |
|
|
|
|
|
|
|
|
if done: |
|
|
st.write("Game Over! Resetting...") |
|
|
env.reset() |
|
|
|