Skip to content

Commit

Permalink
set wide page, column - map, playthrough, player selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Luncenok committed Oct 26, 2024
1 parent 668cd7d commit cd1118a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/llm_postor/demo_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# To run this script, you need to
# `poetry install`
# and then run the following command:
# `poetry run run-gui`
# `poetry run run_gui`

@st.cache_resource
# @st.cache_resource
def load_game_engine():
game_engine = GameEngine()

Expand Down
31 changes: 24 additions & 7 deletions src/llm_postor/game/gui_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pydantic import BaseModel, Field
from streamlit.delta_generator import DeltaGenerator
from annotated_text import annotated_text
import plotly.graph_objects as go
from llm_postor.game.game_state import GameState
from llm_postor.game.game_engine import GameEngine
from llm_postor.game.players.base_player import Player, PlayerRole
Expand All @@ -18,6 +17,7 @@
class GUIHandler(BaseModel):

def display_gui(self, game_engine: GameEngine, chat_analyzer: ChatAnalyzer):
st.set_page_config(page_title="Among Us Game - LLMPostor", layout="wide")
st.title("Among Us Game - LLMPostor")
with st.sidebar:
for i, player in enumerate(game_engine.state.players):
Expand All @@ -31,9 +31,14 @@ def display_gui(self, game_engine: GameEngine, chat_analyzer: ChatAnalyzer):
if st.button("Make Step"):
game_engine.perform_step()
st.rerun()
self._display_map(game_engine.state)
col1, col2 = st.columns([2,1])
with col1:
self._display_map(game_engine.state)
with col2:
with st.container(height=300):
st.text("\n".join(game_engine.state.playthrough))
self._display_player_selection(game_engine.state.players)
st.json(game_engine.state.get_total_cost())
st.text("\n".join(game_engine.state.playthrough))
self._display_annotated_text(game_engine.state)
st.json(game_engine.state.to_dict())

Expand Down Expand Up @@ -126,8 +131,8 @@ def _display_recent_actions(self, player: Player):

def _display_map(self, game_state: GameState):
fig = go.Figure()
img_width = 836 * 2
img_height = 470 * 2
img_width = 836
img_height = 470
scale_factor = 0.5

# Add invisible scatter trace.
Expand Down Expand Up @@ -191,8 +196,8 @@ def update_player_markers(game_state: GameState):

fig.add_trace(
go.Scatter(
x=[x * 200 + random.randint(-20, 20)],
y=[y * 200 + random.randint(-20, 20)],
x=[x * 100 + random.randint(-10, 10)],
y=[y * 100 + random.randint(-10, 10)],
mode="markers",
marker=dict(
color=marker_color,
Expand Down Expand Up @@ -310,3 +315,15 @@ def _display_annotated_text(self, game_state: GameState):
),
" to clarify the situation.",
)

def _display_player_selection(self, players: List[Player]):
selected_player = st.radio(
"Select Player",
[len(players)] + list(range(len(players))),
horizontal=True,
key=f"player_selection_{players}",
format_func=lambda i: players[i].name if i < len(players) else "All",
)
# st.write(f"Selected Player: {players[selected_player].name if selected_player < len(players) else 'All'}")
if selected_player:
st.session_state.selected_player = selected_player

0 comments on commit cd1118a

Please sign in to comment.