Eric Botti commited on
Commit
380be21
·
1 Parent(s): c6c2b98

added streamlit interface

Browse files
Files changed (2) hide show
  1. src/.streamlit/config.toml +3 -0
  2. src/app.py +74 -0
src/.streamlit/config.toml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [theme]
2
+ base="dark"
3
+ font="monospace"
src/app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+
3
+ import streamlit as st
4
+
5
+ from game import Game
6
+
7
+ st.set_page_config(layout="wide", page_title="Chameleon", page_icon="🦎")
8
+
9
+ # CSS
10
+ st.markdown("""
11
+ <style>
12
+ [data-testid="stVerticalBlock"]:has(div.info_container) [data-testid="stMarkdownContainer"] p {
13
+ text-align: center;
14
+ }
15
+ </style>
16
+ """, unsafe_allow_html=True)
17
+
18
+ def display_message(message):
19
+ if message["type"] == "game":
20
+ messages_container.markdown(f"{message['content']}")
21
+ elif message["type"] == "verbose":
22
+ messages_container.markdown(f":green[{message['content']}]")
23
+ elif message["type"] == "debug":
24
+ messages_container.markdown(f":orange[DEBUG: {message['content']}]")
25
+
26
+ class StreamlitGame(Game):
27
+ def human_message(self, message: str):
28
+ message = {"type": "game", "content": message}
29
+ st.session_state["messages"].append(message)
30
+ display_message(message)
31
+
32
+ def verbose_message(self, message: str):
33
+ if self.verbose:
34
+ message = {"type": "verbose", "content": message}
35
+ st.session_state["messages"].append(message)
36
+ display_message(message)
37
+
38
+ def debug_message(self, message: str):
39
+ if self.debug:
40
+ message = {"type": "debug", "content": message}
41
+ st.session_state["messages"].append(message)
42
+ display_message(message)
43
+
44
+
45
+ if "messages" not in st.session_state:
46
+ st.session_state["messages"] = []
47
+ if "game" not in st.session_state:
48
+ st.session_state["game"] = StreamlitGame(verbose=True)
49
+
50
+ margin_size = 1
51
+ center_size = 3
52
+
53
+ title_left, title_center, title_right = st.columns([margin_size, center_size, margin_size])
54
+
55
+ with title_center:
56
+ st.markdown("# :rainbow[Chameleon]")
57
+
58
+ left, center, right = st.columns([margin_size, center_size, margin_size])
59
+
60
+ with center:
61
+ st.write("Welcome to Chameleon! A deduction and deception game powered by LLMs.")
62
+
63
+ start_button = st.button("Start Game")
64
+
65
+ with right:
66
+ st.markdown("### Player Scores")
67
+ for player in st.session_state["game"].players:
68
+ st.write(f"{player.name}: {player.points}")
69
+
70
+
71
+ messages_container = center.container()
72
+
73
+ if start_button:
74
+ asyncio.run(st.session_state["game"].start())