Update app.py
Browse files
app.py
CHANGED
|
@@ -93,6 +93,11 @@ def process_file(input_file):
|
|
| 93 |
error_df = pd.DataFrame({"Error": [f"⚠️ {str(e)}"]})
|
| 94 |
return error_df, None
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Gradio interface
|
| 97 |
with gr.Blocks(title="Schedule Processor") as demo:
|
| 98 |
gr.Markdown("# 📅 Schedule Processor")
|
|
@@ -107,7 +112,6 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 107 |
|
| 108 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 109 |
download_button = gr.Button("Download Processed File", visible=False)
|
| 110 |
-
output_file = gr.File(label="Processed Schedule", visible=False)
|
| 111 |
temp_file_path = gr.State(value=None)
|
| 112 |
|
| 113 |
def reset_components():
|
|
@@ -116,32 +120,30 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 116 |
None, # Clear file input
|
| 117 |
pd.DataFrame(), # Clear output table
|
| 118 |
None, # Reset temp file path
|
| 119 |
-
gr.update(visible=False)
|
| 120 |
-
gr.update(visible=False) # Hide output file
|
| 121 |
]
|
| 122 |
|
| 123 |
def process_and_show(file):
|
| 124 |
df, out_path = process_file(file)
|
| 125 |
if out_path:
|
| 126 |
-
return df, out_path, gr.update(visible=True)
|
| 127 |
-
return df, None, gr.update(visible=False)
|
| 128 |
|
| 129 |
process_btn.click(
|
| 130 |
process_and_show,
|
| 131 |
inputs=input_file,
|
| 132 |
-
outputs=[output_table, temp_file_path, download_button
|
| 133 |
)
|
| 134 |
|
| 135 |
reset_btn.click(
|
| 136 |
reset_components,
|
| 137 |
-
outputs=[input_file, output_table, temp_file_path, download_button
|
| 138 |
)
|
| 139 |
|
| 140 |
-
# Changed to just pass the file path directly
|
| 141 |
download_button.click(
|
| 142 |
-
|
| 143 |
inputs=temp_file_path,
|
| 144 |
-
outputs=
|
| 145 |
)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
|
|
|
| 93 |
error_df = pd.DataFrame({"Error": [f"⚠️ {str(e)}"]})
|
| 94 |
return error_df, None
|
| 95 |
|
| 96 |
+
# Add the missing download_file function
|
| 97 |
+
def download_file(out_path):
|
| 98 |
+
"""Return the processed file path for download"""
|
| 99 |
+
return out_path
|
| 100 |
+
|
| 101 |
# Gradio interface
|
| 102 |
with gr.Blocks(title="Schedule Processor") as demo:
|
| 103 |
gr.Markdown("# 📅 Schedule Processor")
|
|
|
|
| 112 |
|
| 113 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 114 |
download_button = gr.Button("Download Processed File", visible=False)
|
|
|
|
| 115 |
temp_file_path = gr.State(value=None)
|
| 116 |
|
| 117 |
def reset_components():
|
|
|
|
| 120 |
None, # Clear file input
|
| 121 |
pd.DataFrame(), # Clear output table
|
| 122 |
None, # Reset temp file path
|
| 123 |
+
gr.update(visible=False) # Hide download button
|
|
|
|
| 124 |
]
|
| 125 |
|
| 126 |
def process_and_show(file):
|
| 127 |
df, out_path = process_file(file)
|
| 128 |
if out_path:
|
| 129 |
+
return df, out_path, gr.update(visible=True)
|
| 130 |
+
return df, None, gr.update(visible=False)
|
| 131 |
|
| 132 |
process_btn.click(
|
| 133 |
process_and_show,
|
| 134 |
inputs=input_file,
|
| 135 |
+
outputs=[output_table, temp_file_path, download_button]
|
| 136 |
)
|
| 137 |
|
| 138 |
reset_btn.click(
|
| 139 |
reset_components,
|
| 140 |
+
outputs=[input_file, output_table, temp_file_path, download_button]
|
| 141 |
)
|
| 142 |
|
|
|
|
| 143 |
download_button.click(
|
| 144 |
+
download_file,
|
| 145 |
inputs=temp_file_path,
|
| 146 |
+
outputs=gr.File(label="Processed Schedule")
|
| 147 |
)
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|