Zekun Wu commited on
Commit
ce906d2
·
1 Parent(s): 0e52c2c
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -108,12 +108,20 @@ values = st.text_area("Company Values", value="innovation, teamwork, transparenc
108
  batch_size = st.number_input("Batch Size", min_value=1, max_value=100, value=10)
109
  repeat_times = st.number_input("Number of Batches", min_value=1, max_value=10, value=1)
110
 
 
111
  def to_excel(df):
112
  output = BytesIO()
113
- writer = pd.ExcelWriter(output, engine='xlsxwriter')
114
- df.to_excel(writer, index=False, sheet_name='Potshots')
115
- writer.save()
 
 
 
116
  processed_data = output.getvalue()
 
 
 
 
117
  return processed_data
118
 
119
 
 
108
  batch_size = st.number_input("Batch Size", min_value=1, max_value=100, value=10)
109
  repeat_times = st.number_input("Number of Batches", min_value=1, max_value=10, value=1)
110
 
111
+
112
  def to_excel(df):
113
  output = BytesIO()
114
+
115
+ # Use the 'with' statement to handle the file writer and ensure proper closure
116
+ with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
117
+ df.to_excel(writer, index=False, sheet_name='Potshots')
118
+
119
+ # Get the processed data from the buffer
120
  processed_data = output.getvalue()
121
+
122
+ # Reset the buffer for safety (useful if this is reused)
123
+ output.seek(0)
124
+
125
  return processed_data
126
 
127