wb-droid commited on
Commit
fa29ef9
·
1 Parent(s): 8611fe9

minor changes.

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -54,8 +54,9 @@ def play():
54
  img = env.render()
55
  plt.imshow( img )
56
  plt.show()
57
- time.sleep(0.1)
58
- yield (img.copy())
 
59
 
60
  # Run agent on the state
61
  with torch.no_grad():
@@ -72,24 +73,38 @@ def play():
72
  break
73
 
74
  if info["flag_get"]:
75
- break
76
-
 
 
 
 
 
 
 
77
  with gr.Blocks() as demo:
78
  gr.HTML("""<h1 align="center">Mario AI</h1>""")
79
  gr.HTML("""<h1 align="center">(May take a few re-plays to pass full scenario. )</h1>""")
80
  session_data = gr.State([])
81
 
82
  with gr.Row():
 
 
 
 
83
  with gr.Column(scale=1):
84
- play_mario = gr.Button("Play")
85
- with gr.Column(scale=3):
86
- mario_image = gr.Image(height=400,width=400)
87
 
88
-
 
 
 
 
89
  play_mario.click(
90
  play,
91
  [],
92
- [mario_image],
93
  #show_progress=True,
94
 
95
  )
 
54
  img = env.render()
55
  plt.imshow( img )
56
  plt.show()
57
+ #time.sleep(0.1)
58
+ images.append(img.copy())
59
+ yield (img.copy()), None
60
 
61
  # Run agent on the state
62
  with torch.no_grad():
 
73
  break
74
 
75
  if info["flag_get"]:
76
+ #break
77
+ imageio.mimsave('movie_new.gif', images)
78
+ time.sleep(5)
79
+ return (img.copy()), 'movie_new.gif'
80
+
81
+ def refresh_playback():
82
+ return 'movie.gif'
83
+
84
+
85
  with gr.Blocks() as demo:
86
  gr.HTML("""<h1 align="center">Mario AI</h1>""")
87
  gr.HTML("""<h1 align="center">(May take a few re-plays to pass full scenario. )</h1>""")
88
  session_data = gr.State([])
89
 
90
  with gr.Row():
91
+ #with gr.Column(scale=1):
92
+ with gr.Column(scale=1):
93
+ play_mario = gr.Button("Let AI Play")
94
+ mario_image = gr.Image(height=400,width=400, label="New play.")
95
  with gr.Column(scale=1):
96
+ refresh = gr.Button("Refresh")
97
+ mario_gif = gr.Image(height=400,width=400, value='movie.gif', label="Playback previous AI run.")
 
98
 
99
+ refresh.click(
100
+ refresh_playback,
101
+ [],
102
+ [mario_gif]
103
+ )
104
  play_mario.click(
105
  play,
106
  [],
107
+ [mario_image, mario_gif],
108
  #show_progress=True,
109
 
110
  )