File size: 811 Bytes
6bf1d68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()