Update app.py
Browse files
app.py
CHANGED
@@ -104,10 +104,8 @@ def convert_schedule(file_path, direction):
|
|
104 |
# For display, include index as a column
|
105 |
display_df = result.reset_index().rename(columns={'index': first_col_name})
|
106 |
|
107 |
-
# 6. Save to Excel for download
|
108 |
-
|
109 |
-
temp_dir = tempfile.gettempdir()
|
110 |
-
output_filename = os.path.join(temp_dir, f"converted_{uuid.uuid4().hex}.xlsx")
|
111 |
|
112 |
# Clean the DataFrame before saving
|
113 |
result_clean = result.copy()
|
@@ -119,22 +117,21 @@ def convert_schedule(file_path, direction):
|
|
119 |
for col in result_clean.columns:
|
120 |
result_clean[col] = result_clean[col].astype(str)
|
121 |
|
122 |
-
# Save with
|
123 |
try:
|
124 |
-
with
|
125 |
-
|
126 |
|
127 |
-
#
|
128 |
-
if
|
129 |
-
|
|
|
|
|
130 |
|
131 |
except Exception as save_error:
|
132 |
-
# If Excel save fails, try alternative approach
|
133 |
print(f"Excel save error: {save_error}")
|
134 |
-
#
|
135 |
-
|
136 |
-
result_clean.to_csv(csv_filename, index=True)
|
137 |
-
output_filename = csv_filename
|
138 |
|
139 |
# Return both DataFrame and download path
|
140 |
return display_df, output_filename
|
|
|
104 |
# For display, include index as a column
|
105 |
display_df = result.reset_index().rename(columns={'index': first_col_name})
|
106 |
|
107 |
+
# 6. Save to Excel for download - use current directory for Gradio compatibility
|
108 |
+
output_filename = f"converted_{uuid.uuid4().hex}.xlsx"
|
|
|
|
|
109 |
|
110 |
# Clean the DataFrame before saving
|
111 |
result_clean = result.copy()
|
|
|
117 |
for col in result_clean.columns:
|
118 |
result_clean[col] = result_clean[col].astype(str)
|
119 |
|
120 |
+
# Save with better error handling
|
121 |
try:
|
122 |
+
# Use simple to_excel with minimal options for better compatibility
|
123 |
+
result_clean.to_excel(output_filename, index=True, engine='openpyxl')
|
124 |
|
125 |
+
# Return the filename directly for Gradio to handle
|
126 |
+
if os.path.exists(output_filename):
|
127 |
+
print(f"File created successfully: {output_filename}")
|
128 |
+
else:
|
129 |
+
raise FileNotFoundError("File creation failed")
|
130 |
|
131 |
except Exception as save_error:
|
|
|
132 |
print(f"Excel save error: {save_error}")
|
133 |
+
# Return None if save fails
|
134 |
+
return display_df, None
|
|
|
|
|
135 |
|
136 |
# Return both DataFrame and download path
|
137 |
return display_df, output_filename
|