Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +17,7 @@ import math
|
|
17 |
import time
|
18 |
from tqdm import tqdm
|
19 |
from datetime import datetime
|
20 |
-
|
21 |
-
|
22 |
|
23 |
|
24 |
SCREEN_HEIGHT = 600
|
@@ -533,7 +532,7 @@ class Game:
|
|
533 |
pygame.display.update()
|
534 |
|
535 |
|
536 |
-
def play_auto(self):
|
537 |
try:
|
538 |
points_label = 0
|
539 |
for episode in tqdm(range(1, NUM_EPISODES + 1), ascii=True, unit='episodes'):
|
@@ -542,7 +541,7 @@ class Game:
|
|
542 |
current_state = self.get_state()
|
543 |
self.run = True
|
544 |
# Al final de cada episodio, actualiza la interfaz de Streamlit
|
545 |
-
|
546 |
while self.run is True:
|
547 |
|
548 |
for event in pygame.event.get():
|
@@ -658,6 +657,15 @@ class Game:
|
|
658 |
print(f"Modelo duplicado guardado como: {final_model_filename}")
|
659 |
|
660 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
661 |
# Streamlit UI
|
662 |
def streamlit_ui():
|
663 |
st.title('Juego del Dinosaurio con IA')
|
@@ -688,6 +696,10 @@ def streamlit_ui():
|
|
688 |
model_path = os.path.join(model_directory, selected_model_file)
|
689 |
game = Game(EPSILON_INIT, load_model=True, model_path=model_path)
|
690 |
game.play_auto(episode_info)
|
|
|
|
|
|
|
|
|
691 |
|
692 |
# Ejecutar UI
|
693 |
streamlit_ui()
|
|
|
17 |
import time
|
18 |
from tqdm import tqdm
|
19 |
from datetime import datetime
|
20 |
+
import matplotlib.pyplot as plt
|
|
|
21 |
|
22 |
|
23 |
SCREEN_HEIGHT = 600
|
|
|
532 |
pygame.display.update()
|
533 |
|
534 |
|
535 |
+
def play_auto(self,episode_info):
|
536 |
try:
|
537 |
points_label = 0
|
538 |
for episode in tqdm(range(1, NUM_EPISODES + 1), ascii=True, unit='episodes'):
|
|
|
541 |
current_state = self.get_state()
|
542 |
self.run = True
|
543 |
# Al final de cada episodio, actualiza la interfaz de Streamlit
|
544 |
+
episode_info.text(f'Escenario: {episode}, Puntuación actual: {self.points}, Recompensa del episodio: {episode_reward}')
|
545 |
while self.run is True:
|
546 |
|
547 |
for event in pygame.event.get():
|
|
|
657 |
print(f"Modelo duplicado guardado como: {final_model_filename}")
|
658 |
|
659 |
|
660 |
+
def plot_rewards(ep_rewards):
|
661 |
+
plt.figure(figsize=(10, 6))
|
662 |
+
plt.plot(ep_rewards)
|
663 |
+
plt.title("Recompensas por Episodio")
|
664 |
+
plt.xlabel("Episodio")
|
665 |
+
plt.ylabel("Recompensa")
|
666 |
+
st.pyplot(plt)
|
667 |
+
|
668 |
+
|
669 |
# Streamlit UI
|
670 |
def streamlit_ui():
|
671 |
st.title('Juego del Dinosaurio con IA')
|
|
|
696 |
model_path = os.path.join(model_directory, selected_model_file)
|
697 |
game = Game(EPSILON_INIT, load_model=True, model_path=model_path)
|
698 |
game.play_auto(episode_info)
|
699 |
+
|
700 |
+
# Llama a esta función después de que `play_auto` haya terminado
|
701 |
+
if len(game.ep_rewards) > 0:
|
702 |
+
plot_rewards(game.ep_rewards)
|
703 |
|
704 |
# Ejecutar UI
|
705 |
streamlit_ui()
|