Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import base64
|
2 |
import io
|
3 |
-
import os
|
4 |
import zipfile
|
5 |
import logging
|
6 |
from threading import Thread
|
@@ -50,7 +49,7 @@ app.layout = dbc.Container([
|
|
50 |
], className="my-3"),
|
51 |
dbc.Button("Split PDF", id='split-button', color="primary", className="mt-3", disabled=True),
|
52 |
dbc.Progress(id='progress-bar', className="my-3"),
|
53 |
-
dbc.Button("Download ZIP", id='download-button', color="success", className="mt-3"
|
54 |
dcc.Download(id="download-zip"),
|
55 |
html.Div(id='log-output', style={'whiteSpace': 'pre-line'}),
|
56 |
], fluid=True)
|
@@ -105,7 +104,6 @@ def remove_range(n_clicks, existing_ranges):
|
|
105 |
@callback(
|
106 |
Output('progress-bar', 'value'),
|
107 |
Output('log-output', 'children'),
|
108 |
-
Output('download-button', 'disabled'),
|
109 |
Input('split-button', 'n_clicks'),
|
110 |
State('upload-pdf', 'contents'),
|
111 |
State('upload-pdf', 'filename'),
|
@@ -127,7 +125,7 @@ def split_pdf(n_clicks, contents, filename, ranges):
|
|
127 |
thread = Thread(target=process_pdf, args=(contents, filename, ranges))
|
128 |
thread.start()
|
129 |
|
130 |
-
return 0, "PDF splitting process started. Check console for detailed logs."
|
131 |
|
132 |
def process_pdf(contents, filename, ranges):
|
133 |
global progress, generated_file
|
@@ -168,7 +166,6 @@ def process_pdf(contents, filename, ranges):
|
|
168 |
@callback(
|
169 |
Output('progress-bar', 'value', allow_duplicate=True),
|
170 |
Output('log-output', 'children', allow_duplicate=True),
|
171 |
-
Output('download-button', 'disabled', allow_duplicate=True),
|
172 |
Input('progress-bar', 'value'),
|
173 |
prevent_initial_call=True
|
174 |
)
|
@@ -176,12 +173,12 @@ def update_progress(value):
|
|
176 |
global progress
|
177 |
if progress == 100:
|
178 |
logger.info("PDF splitting completed")
|
179 |
-
return 100, "PDF splitting completed. Click 'Download ZIP' to get your files."
|
180 |
elif progress == -1:
|
181 |
logger.error("PDF splitting failed")
|
182 |
-
return 0, "Error occurred during PDF splitting. Check console for details."
|
183 |
else:
|
184 |
-
return progress, f"Processing... {progress:.0f}% complete"
|
185 |
|
186 |
@callback(
|
187 |
Output("download-zip", "data"),
|
|
|
1 |
import base64
|
2 |
import io
|
|
|
3 |
import zipfile
|
4 |
import logging
|
5 |
from threading import Thread
|
|
|
49 |
], className="my-3"),
|
50 |
dbc.Button("Split PDF", id='split-button', color="primary", className="mt-3", disabled=True),
|
51 |
dbc.Progress(id='progress-bar', className="my-3"),
|
52 |
+
dbc.Button("Download ZIP", id='download-button', color="success", className="mt-3"),
|
53 |
dcc.Download(id="download-zip"),
|
54 |
html.Div(id='log-output', style={'whiteSpace': 'pre-line'}),
|
55 |
], fluid=True)
|
|
|
104 |
@callback(
|
105 |
Output('progress-bar', 'value'),
|
106 |
Output('log-output', 'children'),
|
|
|
107 |
Input('split-button', 'n_clicks'),
|
108 |
State('upload-pdf', 'contents'),
|
109 |
State('upload-pdf', 'filename'),
|
|
|
125 |
thread = Thread(target=process_pdf, args=(contents, filename, ranges))
|
126 |
thread.start()
|
127 |
|
128 |
+
return 0, "PDF splitting process started. Check console for detailed logs."
|
129 |
|
130 |
def process_pdf(contents, filename, ranges):
|
131 |
global progress, generated_file
|
|
|
166 |
@callback(
|
167 |
Output('progress-bar', 'value', allow_duplicate=True),
|
168 |
Output('log-output', 'children', allow_duplicate=True),
|
|
|
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, "PDF splitting completed. Click 'Download ZIP' to get your files."
|
177 |
elif progress == -1:
|
178 |
logger.error("PDF splitting failed")
|
179 |
+
return 0, "Error occurred during PDF splitting. Check console for details."
|
180 |
else:
|
181 |
+
return progress, f"Processing... {progress:.0f}% complete"
|
182 |
|
183 |
@callback(
|
184 |
Output("download-zip", "data"),
|