Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import dash
|
|
9 |
import dash_bootstrap_components as dbc
|
10 |
from dash import dcc, html, Input, Output, State, callback, MATCH, ALL
|
11 |
from dash.exceptions import PreventUpdate
|
|
|
12 |
from PyPDF2 import PdfReader, PdfWriter
|
13 |
|
14 |
# Set up logging
|
@@ -53,9 +54,10 @@ app.layout = dbc.Container([
|
|
53 |
], className="my-3"),
|
54 |
dbc.Button("Split PDF", id='split-button', color="primary", className="mt-3", disabled=True),
|
55 |
dbc.Progress(id='progress-bar', className="my-3"),
|
|
|
56 |
dbc.Button("Download ZIP", id='download-button', color="success", className="mt-3", disabled=True),
|
57 |
dcc.Download(id="download-zip"),
|
58 |
-
html.Div(id='log-output', style={'whiteSpace': 'pre-line'}),
|
59 |
], fluid=True)
|
60 |
|
61 |
@callback(
|
@@ -138,6 +140,7 @@ def process_pdf(contents, filename, ranges):
|
|
138 |
Output('progress-bar', 'value'),
|
139 |
Output('download-button', 'disabled'),
|
140 |
Output('log-output', 'children'),
|
|
|
141 |
Input('split-button', 'n_clicks'),
|
142 |
State('upload-pdf', 'contents'),
|
143 |
State('upload-pdf', 'filename'),
|
@@ -156,12 +159,13 @@ def split_pdf(n_clicks, contents, filename, ranges):
|
|
156 |
thread = Thread(target=process_pdf, args=(contents, filename, ranges))
|
157 |
thread.start()
|
158 |
|
159 |
-
return 0, True, "PDF splitting process started. Check console for detailed logs."
|
160 |
|
161 |
@callback(
|
162 |
Output('progress-bar', 'value', allow_duplicate=True),
|
163 |
Output('download-button', 'disabled', allow_duplicate=True),
|
164 |
Output('log-output', 'children', allow_duplicate=True),
|
|
|
165 |
Input('progress-bar', 'value'),
|
166 |
prevent_initial_call=True
|
167 |
)
|
@@ -169,12 +173,12 @@ def update_progress(value):
|
|
169 |
global progress
|
170 |
if progress == 100:
|
171 |
logger.info("PDF splitting completed")
|
172 |
-
return 100, False, "PDF splitting completed. Click 'Download ZIP' to get your files."
|
173 |
elif progress == -1:
|
174 |
logger.error("PDF splitting failed")
|
175 |
-
return 0, True, "Error occurred during PDF splitting. Check console for details."
|
176 |
else:
|
177 |
-
return progress, True, f"Processing... {progress:.0f}% complete"
|
178 |
|
179 |
@callback(
|
180 |
Output("download-zip", "data"),
|
|
|
9 |
import dash_bootstrap_components as dbc
|
10 |
from dash import dcc, html, Input, Output, State, callback, MATCH, ALL
|
11 |
from dash.exceptions import PreventUpdate
|
12 |
+
|
13 |
from PyPDF2 import PdfReader, PdfWriter
|
14 |
|
15 |
# Set up logging
|
|
|
54 |
], className="my-3"),
|
55 |
dbc.Button("Split PDF", id='split-button', color="primary", className="mt-3", disabled=True),
|
56 |
dbc.Progress(id='progress-bar', className="my-3"),
|
57 |
+
dbc.Spinner(html.Div(id='processing-spinner'), color="primary", type="grow"), # Add spinner
|
58 |
dbc.Button("Download ZIP", id='download-button', color="success", className="mt-3", disabled=True),
|
59 |
dcc.Download(id="download-zip"),
|
60 |
+
html.Div(id='log-output', style={'whiteSpace': 'pre-line'}),
|
61 |
], fluid=True)
|
62 |
|
63 |
@callback(
|
|
|
140 |
Output('progress-bar', 'value'),
|
141 |
Output('download-button', 'disabled'),
|
142 |
Output('log-output', 'children'),
|
143 |
+
Output('processing-spinner', 'children'), # Add output for spinner
|
144 |
Input('split-button', 'n_clicks'),
|
145 |
State('upload-pdf', 'contents'),
|
146 |
State('upload-pdf', 'filename'),
|
|
|
159 |
thread = Thread(target=process_pdf, args=(contents, filename, ranges))
|
160 |
thread.start()
|
161 |
|
162 |
+
return 0, True, "PDF splitting process started. Check console for detailed logs.", "Processing..."
|
163 |
|
164 |
@callback(
|
165 |
Output('progress-bar', 'value', allow_duplicate=True),
|
166 |
Output('download-button', 'disabled', allow_duplicate=True),
|
167 |
Output('log-output', 'children', allow_duplicate=True),
|
168 |
+
Output('processing-spinner', 'children', allow_duplicate=True), # Add output for spinner
|
169 |
Input('progress-bar', 'value'),
|
170 |
prevent_initial_call=True
|
171 |
)
|
|
|
173 |
global progress
|
174 |
if progress == 100:
|
175 |
logger.info("PDF splitting completed")
|
176 |
+
return 100, False, "PDF splitting completed. Click 'Download ZIP' to get your files.", ""
|
177 |
elif progress == -1:
|
178 |
logger.error("PDF splitting failed")
|
179 |
+
return 0, True, "Error occurred during PDF splitting. Check console for details.", ""
|
180 |
else:
|
181 |
+
return progress, True, f"Processing... {progress:.0f}% complete", "Processing..."
|
182 |
|
183 |
@callback(
|
184 |
Output("download-zip", "data"),
|