import gradio as gr import torch import numpy as np from stable_baselines3 import PPO import gym from huggingface_hub import hf_hub_download # 从 Hugging Face Hub 下载 Huggy 代理模型 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 # 创建 Gradio Web 界面 demo = gr.Interface( fn=play_huggy, inputs=[], outputs="video", title="Play with my Huggy Agent!" ) demo.launch()