|
import gradio as gr |
|
import torch |
|
import numpy as np |
|
from stable_baselines3 import PPO |
|
import gym |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
model_path = hf_hub_download(repo_id="Peilin00/ppo-Huggy", filename="ppo-Huggy.onnx") |
|
model = PPO.load(model_path) |
|
|
|
def play_huggy(): |
|
env = gym.make("LunarLander-v2", render_mode="rgb_array") |
|
obs, _ = env.reset() |
|
done = False |
|
frames = [] |
|
|
|
while not done: |
|
action, _ = model.predict(obs) |
|
obs, reward, done, info, _ = env.step(action) |
|
frame = env.render() |
|
frames.append(frame) |
|
|
|
env.close() |
|
return frames |
|
|
|
|
|
demo = gr.Interface( |
|
fn=play_huggy, |
|
inputs=[], |
|
outputs="video", |
|
title="Play with my Huggy Agent!" |
|
) |
|
|
|
demo.launch() |
|
|