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