Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -170,3 +170,17 @@ while game_state['rounds_played'] < NUM_ROUNDS and len(game_state['player_cards'
|
|
170 |
f.write('player_cards,ai_cards,player_score,ai_score,rounds_played\n')
|
171 |
f.write(','.join([str(game_state[key]) for key in game_state.keys()]) + '\n')
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
f.write('player_cards,ai_cards,player_score,ai_score,rounds_played\n')
|
171 |
f.write(','.join([str(game_state[key]) for key in game_state.keys()]) + '\n')
|
172 |
|
173 |
+
import base64
|
174 |
+
|
175 |
+
def create_download_link(filename):
|
176 |
+
with open(filename, 'r') as f:
|
177 |
+
text = f.read()
|
178 |
+
b64 = base64.b64encode(text.encode()).decode()
|
179 |
+
href = f'<a href="data:file/txt;base64,{b64}" download="{filename}">Download {filename}</a>'
|
180 |
+
return href
|
181 |
+
|
182 |
+
if st.sidebar.button('Download Game State'):
|
183 |
+
st.sidebar.markdown(create_download_link('game_state.txt'), unsafe_allow_html=True)
|
184 |
+
|
185 |
+
|
186 |
+
|