Update app.py
Browse files
app.py
CHANGED
|
@@ -98,26 +98,41 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 98 |
with gr.Row():
|
| 99 |
input_file = gr.File(label="Upload Schedule File", type="filepath")
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 102 |
download_button = gr.Button("Download Processed File", visible=False)
|
| 103 |
temp_file_path = gr.State(value=None)
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
def process_and_show(file):
|
| 107 |
df, out_path = process_file(file)
|
| 108 |
if out_path:
|
| 109 |
return df, out_path, gr.update(visible=True)
|
| 110 |
return df, None, gr.update(visible=False)
|
| 111 |
-
|
| 112 |
-
def download_file(out_path):
|
| 113 |
-
return out_path
|
| 114 |
|
| 115 |
-
|
|
|
|
| 116 |
process_and_show,
|
| 117 |
inputs=input_file,
|
| 118 |
outputs=[output_table, temp_file_path, download_button]
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
download_button.click(
|
| 122 |
download_file,
|
| 123 |
inputs=temp_file_path,
|
|
@@ -126,4 +141,3 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 126 |
|
| 127 |
if __name__ == "__main__":
|
| 128 |
demo.launch()
|
| 129 |
-
|
|
|
|
| 98 |
with gr.Row():
|
| 99 |
input_file = gr.File(label="Upload Schedule File", type="filepath")
|
| 100 |
|
| 101 |
+
with gr.Row():
|
| 102 |
+
process_btn = gr.Button("Process File", variant="primary")
|
| 103 |
+
reset_btn = gr.Button("Upload New File")
|
| 104 |
+
|
| 105 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 106 |
download_button = gr.Button("Download Processed File", visible=False)
|
| 107 |
temp_file_path = gr.State(value=None)
|
| 108 |
+
|
| 109 |
+
def reset_components():
|
| 110 |
+
"""Reset all components to initial state"""
|
| 111 |
+
return [
|
| 112 |
+
None, # Clear file input
|
| 113 |
+
pd.DataFrame(), # Clear output table
|
| 114 |
+
None, # Reset temp file path
|
| 115 |
+
gr.update(visible=False) # Hide download button
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
def process_and_show(file):
|
| 119 |
df, out_path = process_file(file)
|
| 120 |
if out_path:
|
| 121 |
return df, out_path, gr.update(visible=True)
|
| 122 |
return df, None, gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
# Event handlers
|
| 125 |
+
process_btn.click(
|
| 126 |
process_and_show,
|
| 127 |
inputs=input_file,
|
| 128 |
outputs=[output_table, temp_file_path, download_button]
|
| 129 |
)
|
| 130 |
|
| 131 |
+
reset_btn.click(
|
| 132 |
+
reset_components,
|
| 133 |
+
outputs=[input_file, output_table, temp_file_path, download_button]
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
download_button.click(
|
| 137 |
download_file,
|
| 138 |
inputs=temp_file_path,
|
|
|
|
| 141 |
|
| 142 |
if __name__ == "__main__":
|
| 143 |
demo.launch()
|
|
|