kreemyyyy commited on
Commit
a3f505d
·
verified ·
1 Parent(s): aa72edf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -44
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import pandas as pd
2
  import openpyxl
3
  import gradio as gr
4
- import io
5
- import os
6
 
7
  def convert_schedule(file_path, direction):
8
  try:
@@ -99,7 +97,7 @@ 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 CSV content as string for download
103
  result_clean = result.copy().fillna('OFF')
104
 
105
  # Ensure all values are strings
@@ -113,61 +111,40 @@ def convert_schedule(file_path, direction):
113
 
114
  except Exception as e:
115
  error_df = pd.DataFrame({'Error': [f"Error processing file: {str(e)}"]})
116
- return error_df, "Error occurred during conversion"
117
 
118
- def download_csv(csv_content):
119
- """Helper function to create downloadable CSV"""
120
- if csv_content and csv_content != "Error occurred during conversion":
121
- # Create a temporary file
122
- filename = "converted_schedule.csv"
123
- with open(filename, 'w', newline='', encoding='utf-8') as f:
124
- f.write(csv_content)
125
- return filename
126
- return None
127
-
128
- # Create the interface with blocks for better control
129
  with gr.Blocks(title="7-Day Schedule Converter") as iface:
130
  gr.Markdown("# 7-Day Schedule Converter")
131
- gr.Markdown("Upload a 7-column weekly schedule (Models vs Days) with merged or single headers, then flip between ModelsTexters or Texters→Models.")
132
 
133
  with gr.Row():
134
  with gr.Column():
135
  file_input = gr.File(label='Upload Weekly Schedule (.xlsx)', file_count='single', type='filepath')
136
  direction_input = gr.Radio(['A to B', 'B to A'], label='Convert Direction', value='A to B')
137
  convert_btn = gr.Button("Convert Schedule", variant="primary")
138
-
139
- with gr.Column():
140
- output_df = gr.Dataframe(label='Converted Schedule')
141
- download_btn = gr.Button("Download as CSV", variant="secondary")
142
- download_file = gr.File(label="Download", visible=False)
143
 
144
- # Store CSV content in state
145
- csv_state = gr.State()
146
 
147
- # Convert button click
148
- def convert_and_store(file_path, direction):
149
- display_df, csv_content = convert_schedule(file_path, direction)
150
- return display_df, csv_content
 
 
 
 
 
 
 
 
 
151
 
152
  convert_btn.click(
153
- fn=convert_and_store,
154
  inputs=[file_input, direction_input],
155
- outputs=[output_df, csv_state]
156
- )
157
-
158
- # Download button click
159
- def create_download(csv_content):
160
- if csv_content and csv_content != "Error occurred during conversion":
161
- filename = "converted_schedule.csv"
162
- with open(filename, 'w', newline='', encoding='utf-8') as f:
163
- f.write(csv_content)
164
- return gr.File(value=filename, visible=True)
165
- return gr.File(visible=False)
166
-
167
- download_btn.click(
168
- fn=create_download,
169
- inputs=[csv_state],
170
- outputs=[download_file]
171
  )
172
 
173
  if __name__ == "__main__":
 
1
  import pandas as pd
2
  import openpyxl
3
  import gradio as gr
 
 
4
 
5
  def convert_schedule(file_path, direction):
6
  try:
 
97
  # For display, include index as a column
98
  display_df = result.reset_index().rename(columns={'index': first_col_name})
99
 
100
+ # 6. Create CSV content as string
101
  result_clean = result.copy().fillna('OFF')
102
 
103
  # Ensure all values are strings
 
111
 
112
  except Exception as e:
113
  error_df = pd.DataFrame({'Error': [f"Error processing file: {str(e)}"]})
114
+ return error_df, f"Error: {str(e)}"
115
 
116
+ # Create the interface
 
 
 
 
 
 
 
 
 
 
117
  with gr.Blocks(title="7-Day Schedule Converter") as iface:
118
  gr.Markdown("# 7-Day Schedule Converter")
119
+ gr.Markdown("Upload a 7-column weekly schedule and convert between ModelsTexters")
120
 
121
  with gr.Row():
122
  with gr.Column():
123
  file_input = gr.File(label='Upload Weekly Schedule (.xlsx)', file_count='single', type='filepath')
124
  direction_input = gr.Radio(['A to B', 'B to A'], label='Convert Direction', value='A to B')
125
  convert_btn = gr.Button("Convert Schedule", variant="primary")
 
 
 
 
 
126
 
127
+ with gr.Row():
128
+ output_df = gr.Dataframe(label='Converted Schedule Preview')
129
 
130
+ with gr.Row():
131
+ csv_output = gr.Textbox(
132
+ label="CSV Data - Copy this text and paste into Excel/Google Sheets",
133
+ lines=10,
134
+ max_lines=20,
135
+ placeholder="Converted CSV data will appear here..."
136
+ )
137
+
138
+ gr.Markdown("### Instructions:")
139
+ gr.Markdown("1. After conversion, copy ALL the text from the CSV Data box above")
140
+ gr.Markdown("2. Open Excel or Google Sheets")
141
+ gr.Markdown("3. Paste the data (it will automatically format into columns)")
142
+ gr.Markdown("4. Save as .xlsx file")
143
 
144
  convert_btn.click(
145
+ fn=convert_schedule,
146
  inputs=[file_input, direction_input],
147
+ outputs=[output_df, csv_output]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  )
149
 
150
  if __name__ == "__main__":