Spaces:
Runtime error
Runtime error
Commit
Β·
4b8b1d0
1
Parent(s):
c8c33d6
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,23 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def replay(
|
|
|
|
| 4 |
# Get the correct model
|
| 5 |
if (option == "LunarLander-v2 ππ©βπ"):
|
| 6 |
-
|
| 7 |
elif(option == "CartPole-v1 πΉοΈ"):
|
| 8 |
-
|
| 9 |
elif(option == "Atari Space Invaders πΎ"):
|
| 10 |
-
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
TODO: Next version with live video generation
|
| 14 |
def replay_classical(hf_model_filename, hf_model_id):
|
|
@@ -24,17 +33,29 @@ def replay_classical(hf_model_filename, hf_model_id):
|
|
| 24 |
def replay_atari(hf_model_filename, hf_model_id):
|
| 25 |
"""
|
| 26 |
|
| 27 |
-
#iface = gr.Interface(fn=, inputs="dropdown", outputs="text")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
iface = gr.Interface(
|
| 32 |
replay,
|
| 33 |
[
|
| 34 |
-
gr.inputs.Dropdown(["Atari Space Invaders πΎ", "CartPole-v1 πΉοΈ", "LunarLander-v2 ππ©βπ
|
| 35 |
],
|
| 36 |
-
"video"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from moviepy.editor import *
|
| 4 |
|
| 5 |
+
def replay(option):
|
| 6 |
+
path = ""
|
| 7 |
# Get the correct model
|
| 8 |
if (option == "LunarLander-v2 ππ©βπ"):
|
| 9 |
+
path = "./LunarLander-v2.mp4"
|
| 10 |
elif(option == "CartPole-v1 πΉοΈ"):
|
| 11 |
+
path = "./CartPole-v1.mp4"
|
| 12 |
elif(option == "Atari Space Invaders πΎ"):
|
| 13 |
+
path = "./SpaceInvadersNoFrameskip-v4.mp4"
|
| 14 |
|
| 15 |
+
|
| 16 |
+
# The only turnaround I found (Base64 video pb)
|
| 17 |
+
videoclip = VideoFileClip(path)
|
| 18 |
+
videoclip.write_videofile("new_filename.mp4")
|
| 19 |
+
return 'new_filename.mp4'
|
| 20 |
+
|
| 21 |
"""
|
| 22 |
TODO: Next version with live video generation
|
| 23 |
def replay_classical(hf_model_filename, hf_model_id):
|
|
|
|
| 33 |
def replay_atari(hf_model_filename, hf_model_id):
|
| 34 |
"""
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
iface = gr.Interface(
|
| 37 |
replay,
|
| 38 |
[
|
| 39 |
+
gr.inputs.Dropdown(["Atari Space Invaders πΎ", "CartPole-v1 πΉοΈ", "LunarLander-v2 ππ©βπ"]),
|
| 40 |
],
|
| 41 |
+
"video",
|
| 42 |
+
title = 'Stable Baselines 3 with π€',
|
| 43 |
+
description = '',
|
| 44 |
+
article =
|
| 45 |
+
'''<div>
|
| 46 |
+
<p style="text-align: center">This version of the RL library contains allows you to load models directly from the Hugging Face Hub</p>
|
| 47 |
+
<p style="text-align: center"> Select the trained agent you want to watch perform.
|
| 48 |
+
These models are from <a href="https://github.com/araffin/rl-baselines-zoo">Stable Baseline Zoo</a></p>
|
| 49 |
+
<p>
|
| 50 |
+
There are currently 3 models:
|
| 51 |
+
<ul>
|
| 52 |
+
<li><a href="https://huggingface.co/ThomasSimonini/stable-baselines3-ppo-SpaceInvadersNoFrameskip-v4">PPO SpaceInvadersNoFrameskip-v4</a></li>
|
| 53 |
+
<li><a href="https://huggingface.co/ThomasSimonini/stable-baselines3-ppo-LunarLander-v2">PPO LunarLander-v2</a></li>
|
| 54 |
+
<li><a href="https://huggingface.co/ThomasSimonini/stable-baselines3-ppo-CartPole-v1">PPO CartPole-v1</a></li>
|
| 55 |
+
</ul>
|
| 56 |
+
</div>'''
|
| 57 |
+
)
|
| 58 |
|
|
|
|
| 59 |
|
| 60 |
+
iface.launch()
|
| 61 |
+
|