kreemyyyy commited on
Commit
08e947a
·
verified ·
1 Parent(s): b91456d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -3,6 +3,7 @@ import openpyxl
3
  import gradio as gr
4
  import io
5
  import base64
 
6
 
7
  def convert_schedule(file_path, direction):
8
  try:
@@ -99,30 +100,21 @@ def convert_schedule(file_path, direction):
99
  # For display, include index as a column
100
  display_df = result.reset_index().rename(columns={'index': first_col_name})
101
 
102
- # 6. Create Excel file in memory
103
- output_buffer = io.BytesIO()
104
  result_clean = result.copy().fillna('OFF')
105
 
106
  # Ensure all values are strings
107
  for col in result_clean.columns:
108
  result_clean[col] = result_clean[col].astype(str)
109
-
110
- # Write to buffer
111
- result_clean.to_excel(output_buffer, index=True, engine='openpyxl')
112
- output_buffer.seek(0)
113
-
114
- # Save buffer content to a temporary file that Gradio can serve
115
- temp_filename = "converted_schedule.xlsx"
116
- with open(temp_filename, 'wb') as f:
117
- f.write(output_buffer.getvalue())
118
 
119
- return display_df, temp_filename
 
120
 
121
  except Exception as e:
122
  error_df = pd.DataFrame({'Error': [f"Error processing file: {str(e)}"]})
123
  return error_df, None
124
 
125
- # Gradio interface
126
  iface = gr.Interface(
127
  fn=convert_schedule,
128
  inputs=[
@@ -130,13 +122,14 @@ iface = gr.Interface(
130
  gr.Radio(['A to B', 'B to A'], label='Convert Direction', value='A to B')
131
  ],
132
  outputs=[
133
- gr.Dataframe(label='Converted Schedule'),
134
- gr.File(label='Download Converted Excel')
135
  ],
136
  title='7-Day Schedule Converter',
137
  description=(
138
  'Upload a 7-column weekly schedule (Models vs Days) with merged or single headers, '
139
- 'then flip between Models→Texters or Texters→Models. Download the result as .xlsx.'
 
140
  ),
141
  flagging_mode='never'
142
  )
 
3
  import gradio as gr
4
  import io
5
  import base64
6
+ from datetime import datetime
7
 
8
  def convert_schedule(file_path, direction):
9
  try:
 
100
  # For display, include index as a column
101
  display_df = result.reset_index().rename(columns={'index': first_col_name})
102
 
103
+ # 6. Return the DataFrame for download - let Gradio handle the file creation
 
104
  result_clean = result.copy().fillna('OFF')
105
 
106
  # Ensure all values are strings
107
  for col in result_clean.columns:
108
  result_clean[col] = result_clean[col].astype(str)
 
 
 
 
 
 
 
 
 
109
 
110
+ # Return the cleaned DataFrame directly - Gradio will convert it
111
+ return display_df, result_clean
112
 
113
  except Exception as e:
114
  error_df = pd.DataFrame({'Error': [f"Error processing file: {str(e)}"]})
115
  return error_df, None
116
 
117
+ # Gradio interface with different output types
118
  iface = gr.Interface(
119
  fn=convert_schedule,
120
  inputs=[
 
122
  gr.Radio(['A to B', 'B to A'], label='Convert Direction', value='A to B')
123
  ],
124
  outputs=[
125
+ gr.Dataframe(label='Converted Schedule (Preview)'),
126
+ gr.Dataframe(label='Download Data (Right-click to copy/export)', type='pandas')
127
  ],
128
  title='7-Day Schedule Converter',
129
  description=(
130
  'Upload a 7-column weekly schedule (Models vs Days) with merged or single headers, '
131
+ 'then flip between Models→Texters or Texters→Models. '
132
+ 'Use the second table to copy the data or export it manually.'
133
  ),
134
  flagging_mode='never'
135
  )