Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -242,13 +242,14 @@ def update_shred_upload(contents, delete_clicks, filename, stored_data):
|
|
242 |
if trig_id == "shred-upload":
|
243 |
if contents and filename:
|
244 |
logger.info(f"Document uploaded in Shred: {filename}")
|
245 |
-
|
246 |
preview = html.Div([
|
247 |
html.B(f"Uploaded: {filename}"),
|
248 |
html.Br(),
|
249 |
-
html.Div(
|
250 |
])
|
251 |
-
|
|
|
252 |
else:
|
253 |
return None, "", {"display": "none"}
|
254 |
elif trig_id == "shred-delete-btn":
|
@@ -294,10 +295,11 @@ def handle_all_tabs(*args):
|
|
294 |
logger.info(f"Generate Shred button pressed for {tab_id}")
|
295 |
shred_data = args[shred_upload_store_idx]
|
296 |
instr = args[instr_idx] or ""
|
297 |
-
if shred_data and "
|
298 |
-
doc =
|
299 |
logger.info(f"Shred document will be sent to Anthropic with instructions: {instr}")
|
300 |
content, df = generate_content(doc, "Shred", instr)
|
|
|
301 |
if not df.empty:
|
302 |
outputs[out_idx] = dash_table.DataTable(
|
303 |
data=df.to_dict('records'),
|
@@ -315,13 +317,13 @@ def handle_all_tabs(*args):
|
|
315 |
outputs[out_idx] = "Please upload a document to begin."
|
316 |
elif trig == shred_dl_btn:
|
317 |
prev_output = args[prev_output_idx]
|
318 |
-
|
319 |
-
if prev_output and hasattr(prev_output, 'props') and 'data' in prev_output.props:
|
320 |
df = pd.DataFrame(prev_output.props['data'])
|
321 |
buffer = BytesIO()
|
322 |
df.to_csv(buffer, index=False)
|
323 |
outputs[dl_idx] = dcc.send_bytes(buffer.getvalue(), f"{tab_id}_report.csv")
|
324 |
elif prev_output:
|
|
|
325 |
buffer = BytesIO(prev_output.encode("utf-8") if isinstance(prev_output, str) else b"")
|
326 |
outputs[dl_idx] = dcc.send_bytes(buffer.getvalue(), f"{tab_id}_report.txt")
|
327 |
else:
|
|
|
242 |
if trig_id == "shred-upload":
|
243 |
if contents and filename:
|
244 |
logger.info(f"Document uploaded in Shred: {filename}")
|
245 |
+
full_text = process_document(contents, filename)
|
246 |
preview = html.Div([
|
247 |
html.B(f"Uploaded: {filename}"),
|
248 |
html.Br(),
|
249 |
+
html.Div(full_text[:2000] + ("..." if len(full_text) > 2000 else ""), style={"whiteSpace": "pre-wrap", "overflowWrap": "break-word", "fontSize": "small"})
|
250 |
])
|
251 |
+
# Store the full document text, filename, and preview
|
252 |
+
return {"contents": contents, "filename": filename, "full_text": full_text, "preview": full_text[:2000]}, preview, {"display": "block"}
|
253 |
else:
|
254 |
return None, "", {"display": "none"}
|
255 |
elif trig_id == "shred-delete-btn":
|
|
|
295 |
logger.info(f"Generate Shred button pressed for {tab_id}")
|
296 |
shred_data = args[shred_upload_store_idx]
|
297 |
instr = args[instr_idx] or ""
|
298 |
+
if shred_data and "full_text" in shred_data and shred_data["full_text"]:
|
299 |
+
doc = shred_data["full_text"]
|
300 |
logger.info(f"Shred document will be sent to Anthropic with instructions: {instr}")
|
301 |
content, df = generate_content(doc, "Shred", instr)
|
302 |
+
# Store Anthropic result in outputs
|
303 |
if not df.empty:
|
304 |
outputs[out_idx] = dash_table.DataTable(
|
305 |
data=df.to_dict('records'),
|
|
|
317 |
outputs[out_idx] = "Please upload a document to begin."
|
318 |
elif trig == shred_dl_btn:
|
319 |
prev_output = args[prev_output_idx]
|
320 |
+
if (hasattr(prev_output, 'props') and 'data' in prev_output.props):
|
|
|
321 |
df = pd.DataFrame(prev_output.props['data'])
|
322 |
buffer = BytesIO()
|
323 |
df.to_csv(buffer, index=False)
|
324 |
outputs[dl_idx] = dcc.send_bytes(buffer.getvalue(), f"{tab_id}_report.csv")
|
325 |
elif prev_output:
|
326 |
+
# If prev_output is markdown or text
|
327 |
buffer = BytesIO(prev_output.encode("utf-8") if isinstance(prev_output, str) else b"")
|
328 |
outputs[dl_idx] = dcc.send_bytes(buffer.getvalue(), f"{tab_id}_report.txt")
|
329 |
else:
|