kreemyyyy commited on
Commit
e27b63a
·
verified ·
1 Parent(s): 835c782

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -55,6 +55,7 @@ def convert_schedule(file_path, direction):
55
  assignments[texter][day].append(model)
56
  index = sorted(assignments.keys())
57
  result = pd.DataFrame(index=index, columns=day_cols)
 
58
  for texter, days_map in assignments.items():
59
  for day in day_cols:
60
  models = days_map.get(day, [])
@@ -72,45 +73,43 @@ def convert_schedule(file_path, direction):
72
  assignments[model][day].append(texter)
73
  index = sorted(assignments.keys())
74
  result = pd.DataFrame(index=index, columns=day_cols)
 
75
  for model, days_map in assignments.items():
76
  for day in day_cols:
77
  texters = days_map.get(day, [])
78
  result.at[model, day] = ', '.join(texters) if texters else 'OFF'
79
 
80
- # 5. Cleanup axis names
81
  result.index.name = None
82
  result.columns.name = None
83
 
84
- # 6. Save to Excel for download in the current working directory
 
 
 
85
  output_filename = f"converted_{uuid.uuid4().hex}.xlsx"
86
- output_path = os.path.join(os.getcwd(), output_filename)
87
- result.to_excel(output_path, engine='openpyxl', index=True)
88
 
89
  # Return both DataFrame and download path
90
- return result, output_path
91
-
92
- # Gradio UI definition
93
-
94
- def main():
95
- iface = gr.Interface(
96
- fn=convert_schedule,
97
- inputs=[
98
- gr.File(label='Upload Weekly Schedule (.xlsx)', file_count='single', type='filepath'),
99
- gr.Radio(['A to B', 'B to A'], label='Convert Direction')
100
- ],
101
- outputs=[
102
- gr.Dataframe(label='Converted Schedule'),
103
- gr.File(label='Download Converted Excel')
104
- ],
105
- title='7-Day Schedule Converter',
106
- description=(
107
- 'Upload a 7-column weekly schedule (Models vs Days) with merged or single headers, '
108
- 'then flip between Models→Texters or Texters→Models. Download the result as .xlsx.'
109
- ),
110
- allow_flagging='never'
111
- )
112
- iface.launch(server_name='0.0.0.0', server_port=7860)
113
 
114
- # Call main to start the app
115
- if __name__ == '__main__':
116
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  assignments[texter][day].append(model)
56
  index = sorted(assignments.keys())
57
  result = pd.DataFrame(index=index, columns=day_cols)
58
+ first_col_name = 'Texter'
59
  for texter, days_map in assignments.items():
60
  for day in day_cols:
61
  models = days_map.get(day, [])
 
73
  assignments[model][day].append(texter)
74
  index = sorted(assignments.keys())
75
  result = pd.DataFrame(index=index, columns=day_cols)
76
+ first_col_name = 'Model'
77
  for model, days_map in assignments.items():
78
  for day in day_cols:
79
  texters = days_map.get(day, [])
80
  result.at[model, day] = ', '.join(texters) if texters else 'OFF'
81
 
82
+ # 5. Cleanup axis names
83
  result.index.name = None
84
  result.columns.name = None
85
 
86
+ # For display, include index as a column
87
+ display_df = result.reset_index().rename(columns={'index': first_col_name})
88
+
89
+ # 6. Save to Excel for download (relative path so Gradio can serve it)
90
  output_filename = f"converted_{uuid.uuid4().hex}.xlsx"
91
+ result.to_excel(output_filename, engine='openpyxl', index=True)
 
92
 
93
  # Return both DataFrame and download path
94
+ return display_df, output_filename
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ # Build Gradio interface and launch immediately for Hugging Face Spaces
97
+ iface = gr.Interface(
98
+ fn=convert_schedule,
99
+ inputs=[
100
+ gr.File(label='Upload Weekly Schedule (.xlsx)', file_count='single', type='filepath'),
101
+ gr.Radio(['A to B', 'B to A'], label='Convert Direction')
102
+ ],
103
+ outputs=[
104
+ gr.Dataframe(label='Converted Schedule'),
105
+ gr.File(label='Download Converted Excel')
106
+ ],
107
+ title='7-Day Schedule Converter',
108
+ description=(
109
+ 'Upload a 7-column weekly schedule (Models vs Days) with merged or single headers, '
110
+ 'then flip between Models→Texters or Texters→Models. Download the result as .xlsx.'
111
+ ),
112
+ flagging_mode='never'
113
+ )
114
+ # Launch on 0.0.0.0:7860 for Spaces
115
+ iface.launch(server_name='0.0.0.0', server_port=7860)