kreemyyyy commited on
Commit
d52e72f
Β·
verified Β·
1 Parent(s): 04f5c5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -110,23 +110,20 @@ def convert_schedule(file_path, direction):
110
  for col in result_clean.columns:
111
  result_clean[col] = result_clean[col].astype(str)
112
 
113
- # Create Excel file in memory
114
  download_df = result_clean.reset_index().rename(columns={'index': first_col_name})
115
 
116
- # Use BytesIO to create file in memory
117
- excel_buffer = io.BytesIO()
118
-
119
- with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
120
- download_df.to_excel(writer, sheet_name='Converted Schedule', index=False)
121
-
122
- excel_buffer.seek(0)
123
 
124
  # Create filename with timestamp
125
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
126
- filename = f"converted_schedule_{timestamp}.xlsx"
127
 
128
- # Return the buffer content for download
129
- return display_df, (excel_buffer.getvalue(), filename)
130
 
131
  except Exception as e:
132
  error_msg = f"Error processing file: {str(e)}"
@@ -151,8 +148,9 @@ def process_and_download(file_path, direction):
151
  temp_dir = tempfile.gettempdir()
152
  temp_path = os.path.join(temp_dir, filename)
153
 
154
- with open(temp_path, 'wb') as f:
155
- f.write(excel_content)
 
156
 
157
  return display_result, temp_path
158
 
@@ -174,7 +172,7 @@ iface = gr.Interface(
174
  ],
175
  outputs=[
176
  gr.Dataframe(label='Converted Schedule (Preview)', wrap=True),
177
- gr.File(label='Download Converted Schedule (.xlsx)')
178
  ],
179
  title='πŸ”„ 7-Day Schedule Converter',
180
  description=(
 
110
  for col in result_clean.columns:
111
  result_clean[col] = result_clean[col].astype(str)
112
 
113
+ # Create CSV file in memory (more reliable than Excel)
114
  download_df = result_clean.reset_index().rename(columns={'index': first_col_name})
115
 
116
+ # Create CSV content
117
+ csv_buffer = io.StringIO()
118
+ download_df.to_csv(csv_buffer, index=False)
119
+ csv_content = csv_buffer.getvalue()
 
 
 
120
 
121
  # Create filename with timestamp
122
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
123
+ filename = f"converted_schedule_{timestamp}.csv"
124
 
125
+ # Return the CSV content for download
126
+ return display_df, (csv_content.encode('utf-8'), filename)
127
 
128
  except Exception as e:
129
  error_msg = f"Error processing file: {str(e)}"
 
148
  temp_dir = tempfile.gettempdir()
149
  temp_path = os.path.join(temp_dir, filename)
150
 
151
+ # Write CSV content
152
+ with open(temp_path, 'w', encoding='utf-8') as f:
153
+ f.write(excel_content.decode('utf-8'))
154
 
155
  return display_result, temp_path
156
 
 
172
  ],
173
  outputs=[
174
  gr.Dataframe(label='Converted Schedule (Preview)', wrap=True),
175
+ gr.File(label='Download Converted Schedule (.csv)')
176
  ],
177
  title='πŸ”„ 7-Day Schedule Converter',
178
  description=(