ThomasFfefefef commited on
Commit
4b8b1d0
Β·
1 Parent(s): c8c33d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -12
app.py CHANGED
@@ -1,14 +1,23 @@
1
  import gradio as gr
 
 
2
 
3
- def replay(name):
 
4
  # Get the correct model
5
  if (option == "LunarLander-v2 πŸš€πŸ‘©β€πŸš€"):
6
- return "./LunarLander-v2.mp4"
7
  elif(option == "CartPole-v1 πŸ•ΉοΈ"):
8
- return "./CartPole-v1.mp4"
9
  elif(option == "Atari Space Invaders πŸ‘Ύ"):
10
- return "./SpaceInvadersNoFrameskip-v4.mp4"
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
+