Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -61,14 +61,46 @@ app.layout = dbc.Container([
|
|
61 |
], fluid=True)
|
62 |
|
63 |
@callback(
|
|
|
64 |
Output('split-button', 'disabled'),
|
65 |
-
Input('upload-pdf', 'contents')
|
|
|
66 |
)
|
67 |
-
def
|
68 |
-
if contents:
|
69 |
-
logger.info("PDF uploaded
|
70 |
-
return False
|
71 |
-
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
@callback(
|
74 |
Output('progress-bar', 'value'),
|
|
|
61 |
], fluid=True)
|
62 |
|
63 |
@callback(
|
64 |
+
Output('pdf-name', 'children'),
|
65 |
Output('split-button', 'disabled'),
|
66 |
+
Input('upload-pdf', 'contents'),
|
67 |
+
Input('upload-pdf', 'filename')
|
68 |
)
|
69 |
+
def update_output(contents, filename):
|
70 |
+
if contents is not None:
|
71 |
+
logger.info(f"PDF uploaded: {filename}")
|
72 |
+
return html.Div(f"Uploaded: {filename}"), False
|
73 |
+
return "", True
|
74 |
+
|
75 |
+
@callback(
|
76 |
+
Output('ranges-container', 'children'),
|
77 |
+
Input('add-range', 'n_clicks'),
|
78 |
+
State('ranges-container', 'children'),
|
79 |
+
prevent_initial_call=True
|
80 |
+
)
|
81 |
+
def add_range(n_clicks, existing_ranges):
|
82 |
+
if n_clicks:
|
83 |
+
new_index = len(existing_ranges)
|
84 |
+
new_range = dbc.Row([
|
85 |
+
dbc.Col(dbc.Input(id={'type': 'range-input', 'index': new_index}, type='text', placeholder='Enter page range (e.g., 1-3)'), width=10),
|
86 |
+
dbc.Col(dbc.Button("Remove", id={'type': 'remove-range', 'index': new_index}, color="danger", size="sm"), width=2),
|
87 |
+
], className="mb-2")
|
88 |
+
existing_ranges.append(new_range)
|
89 |
+
return existing_ranges
|
90 |
+
|
91 |
+
@callback(
|
92 |
+
Output('ranges-container', 'children', allow_duplicate=True),
|
93 |
+
Input({'type': 'remove-range', 'index': ALL}, 'n_clicks'),
|
94 |
+
State('ranges-container', 'children'),
|
95 |
+
prevent_initial_call=True
|
96 |
+
)
|
97 |
+
def remove_range(n_clicks, existing_ranges):
|
98 |
+
ctx = dash.callback_context
|
99 |
+
if not ctx.triggered:
|
100 |
+
raise PreventUpdate
|
101 |
+
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
102 |
+
index_to_remove = json.loads(button_id)['index']
|
103 |
+
return [range for i, range in enumerate(existing_ranges) if i != index_to_remove]
|
104 |
|
105 |
@callback(
|
106 |
Output('progress-bar', 'value'),
|