Spaces:
Paused
Paused
added a stop processing button to kill processing mid way
Browse files
src/ui.py
CHANGED
|
@@ -74,6 +74,8 @@ def create_ui():
|
|
| 74 |
.page-navigation { text-align: center; margin-top: 1rem; }
|
| 75 |
.page-navigation button { margin: 0 0.5rem; }
|
| 76 |
.page-info { display: inline-block; margin: 0 1rem; }
|
|
|
|
|
|
|
| 77 |
""") as demo:
|
| 78 |
gr.Markdown("Doc2Md: Convert any documents to Markdown")
|
| 79 |
|
|
@@ -96,6 +98,13 @@ def create_ui():
|
|
| 96 |
|
| 97 |
file_download = gr.File(label="Download File")
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
convert_button = gr.Button("Convert")
|
| 100 |
|
| 101 |
with gr.Tab("Config ⚙️"):
|
|
@@ -142,10 +151,37 @@ def create_ui():
|
|
| 142 |
outputs=[ocr_dropdown]
|
| 143 |
)
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
convert_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
fn=handle_convert,
|
| 147 |
inputs=[file_input, provider_dropdown, ocr_dropdown, output_format],
|
| 148 |
outputs=[file_display, file_download, content_pages, current_page, page_info, navigation_row]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
)
|
| 150 |
|
| 151 |
prev_btn.click(
|
|
|
|
| 74 |
.page-navigation { text-align: center; margin-top: 1rem; }
|
| 75 |
.page-navigation button { margin: 0 0.5rem; }
|
| 76 |
.page-info { display: inline-block; margin: 0 1rem; }
|
| 77 |
+
.processing-indicator { display: flex; align-items: center; gap: 10px; }
|
| 78 |
+
.cancel-btn { background-color: #ff4d4f; color: white; }
|
| 79 |
""") as demo:
|
| 80 |
gr.Markdown("Doc2Md: Convert any documents to Markdown")
|
| 81 |
|
|
|
|
| 98 |
|
| 99 |
file_download = gr.File(label="Download File")
|
| 100 |
|
| 101 |
+
# Add processing indicator and cancel button
|
| 102 |
+
with gr.Row(visible=False) as processing_row:
|
| 103 |
+
with gr.Column(scale=3):
|
| 104 |
+
processing_indicator = gr.Markdown("Processing document... This may take a while.", elem_classes=["processing-indicator"])
|
| 105 |
+
with gr.Column(scale=1):
|
| 106 |
+
cancel_btn = gr.Button("Cancel", elem_classes=["cancel-btn"])
|
| 107 |
+
|
| 108 |
convert_button = gr.Button("Convert")
|
| 109 |
|
| 110 |
with gr.Tab("Config ⚙️"):
|
|
|
|
| 151 |
outputs=[ocr_dropdown]
|
| 152 |
)
|
| 153 |
|
| 154 |
+
def start_processing():
|
| 155 |
+
return gr.update(visible=True), gr.update(interactive=False)
|
| 156 |
+
|
| 157 |
+
def end_processing():
|
| 158 |
+
return gr.update(visible=False), gr.update(interactive=True)
|
| 159 |
+
|
| 160 |
convert_button.click(
|
| 161 |
+
fn=start_processing,
|
| 162 |
+
inputs=None,
|
| 163 |
+
outputs=[processing_row, convert_button],
|
| 164 |
+
queue=False
|
| 165 |
+
).then(
|
| 166 |
fn=handle_convert,
|
| 167 |
inputs=[file_input, provider_dropdown, ocr_dropdown, output_format],
|
| 168 |
outputs=[file_display, file_download, content_pages, current_page, page_info, navigation_row]
|
| 169 |
+
).then(
|
| 170 |
+
fn=end_processing,
|
| 171 |
+
inputs=None,
|
| 172 |
+
outputs=[processing_row, convert_button]
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
# Add cancel button functionality
|
| 176 |
+
cancel_btn.click(
|
| 177 |
+
fn=lambda: None,
|
| 178 |
+
inputs=None,
|
| 179 |
+
outputs=None,
|
| 180 |
+
cancels=[convert_button]
|
| 181 |
+
).then(
|
| 182 |
+
fn=end_processing,
|
| 183 |
+
inputs=None,
|
| 184 |
+
outputs=[processing_row, convert_button]
|
| 185 |
)
|
| 186 |
|
| 187 |
prev_btn.click(
|