awacke1 commited on
Commit
4d5c18e
โ€ข
1 Parent(s): a7e116a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -125,7 +125,7 @@ def play_game(num_games):
125
  st.write(f"{attributes['sketch']} {attributes['character']}: {attributes['score']} successful attacks, {attributes['health_tokens']} health tokens, {attributes['coin']} coins")
126
  for problem, score in health_problem_scores.items():
127
  st.write(f"{problem}: {score} defeats")
128
- # Display a button to download the game state CSV file
129
  if os.path.exists("game_state.csv"):
130
  st.write("# Download Game State")
131
  files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(".csv")]
@@ -135,11 +135,11 @@ def play_game(num_games):
135
  file_to_delete = st.selectbox("Select a file to delete", files)
136
  if st.button("Delete File"):
137
  os.remove(file_to_delete)
138
- if st.button("Download Game State"):
139
- with open("game_state.csv", "r") as f:
140
- csv_data = f.read()
141
- st.download_button("game_state.csv", csv_data, file_name="game_state.csv", mime="text/csv")
142
  st.write("*Note: Downloaded files are saved in your browser's default download location*")
 
143
 
144
  # Define the Streamlit app
145
  def app():
 
125
  st.write(f"{attributes['sketch']} {attributes['character']}: {attributes['score']} successful attacks, {attributes['health_tokens']} health tokens, {attributes['coin']} coins")
126
  for problem, score in health_problem_scores.items():
127
  st.write(f"{problem}: {score} defeats")
128
+ # Display a link to download the game state CSV file
129
  if os.path.exists("game_state.csv"):
130
  st.write("# Download Game State")
131
  files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(".csv")]
 
135
  file_to_delete = st.selectbox("Select a file to delete", files)
136
  if st.button("Delete File"):
137
  os.remove(file_to_delete)
138
+ with open("game_state.csv", "r") as f:
139
+ csv_data = f.read()
140
+ st.markdown(f"<a href='data:text/csv;base64,{base64.b64encode(csv_data.encode()).decode()}' download='game_state.csv'>Download Game State</a>", unsafe_allow_html=True)
 
141
  st.write("*Note: Downloaded files are saved in your browser's default download location*")
142
+
143
 
144
  # Define the Streamlit app
145
  def app():