Update app.py
Browse files
app.py
CHANGED
|
@@ -76,20 +76,34 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 76 |
input_file = gr.File(label="Upload Schedule File", type="filepath")
|
| 77 |
|
| 78 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 79 |
-
|
| 80 |
btn = gr.Button("Process File")
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
def process_and_show(file):
|
| 83 |
df, out_path = process_file(file)
|
| 84 |
if out_path:
|
| 85 |
-
|
| 86 |
-
|
|
|
|
| 87 |
|
|
|
|
|
|
|
|
|
|
| 88 |
btn.click(
|
| 89 |
process_and_show,
|
| 90 |
inputs=input_file,
|
| 91 |
-
outputs=[output_table,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
-
demo.launch(
|
|
|
|
|
|
| 76 |
input_file = gr.File(label="Upload Schedule File", type="filepath")
|
| 77 |
|
| 78 |
output_table = gr.Dataframe(label="Preview", wrap=True)
|
| 79 |
+
download_button = gr.Button("Download Processed File", visible=False)
|
| 80 |
btn = gr.Button("Process File")
|
| 81 |
|
| 82 |
+
# State to store processed file path
|
| 83 |
+
temp_file_path = gr.State()
|
| 84 |
+
|
| 85 |
def process_and_show(file):
|
| 86 |
df, out_path = process_file(file)
|
| 87 |
if out_path:
|
| 88 |
+
temp_file_path.set(out_path) # Save file path for download
|
| 89 |
+
return df, gr.update(visible=True)
|
| 90 |
+
return df, gr.update(visible=False)
|
| 91 |
|
| 92 |
+
def download_file():
|
| 93 |
+
return temp_file_path.get() # Return the stored file path
|
| 94 |
+
|
| 95 |
btn.click(
|
| 96 |
process_and_show,
|
| 97 |
inputs=input_file,
|
| 98 |
+
outputs=[output_table, download_button]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
download_button.click(
|
| 102 |
+
download_file,
|
| 103 |
+
inputs=None,
|
| 104 |
+
outputs=gr.File(label="Processed Schedule")
|
| 105 |
)
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
+
demo.launch()
|
| 109 |
+
|