Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import base64
|
| 3 |
import io
|
| 4 |
import dash
|
| 5 |
-
from dash import dcc, html, Input, Output, State, callback_context,
|
| 6 |
import dash_bootstrap_components as dbc
|
| 7 |
import pandas as pd
|
| 8 |
import logging
|
|
@@ -679,20 +679,19 @@ def unified_master_callback(
|
|
| 679 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
| 680 |
uploaded_rfp_decoded_bytes = None
|
| 681 |
|
| 682 |
-
|
| 683 |
is_doc_delete = False
|
| 684 |
is_proposal_delete = False
|
| 685 |
doc_del_filename = None
|
| 686 |
proposal_del_filename = None
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
if
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
proposal_del_filename = triggered_id_dict.get('index')
|
| 696 |
|
| 697 |
if is_doc_delete and doc_del_filename:
|
| 698 |
if doc_del_filename in sess_data["uploaded_documents"]:
|
|
@@ -749,7 +748,7 @@ def unified_master_callback(
|
|
| 749 |
doc_delete_clicks = safe_get_n_clicks(ctx, 8)
|
| 750 |
proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
|
| 751 |
|
| 752 |
-
if not ctx.triggered or (ctx
|
| 753 |
doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
|
| 754 |
doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
|
| 755 |
proposal_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["proposals"].keys()]
|
|
@@ -763,7 +762,7 @@ def unified_master_callback(
|
|
| 763 |
"expanded"
|
| 764 |
)
|
| 765 |
|
| 766 |
-
if ctx
|
| 767 |
lock = sess_data.get("gemini_lock")
|
| 768 |
if lock and lock.locked():
|
| 769 |
try:
|
|
@@ -785,7 +784,7 @@ def unified_master_callback(
|
|
| 785 |
"expanded"
|
| 786 |
)
|
| 787 |
|
| 788 |
-
if ctx
|
| 789 |
content_type, content_string = rfp_content.split(',')
|
| 790 |
decoded = base64.b64decode(content_string)
|
| 791 |
uploaded_rfp_decoded_bytes = decoded
|
|
@@ -802,7 +801,7 @@ def unified_master_callback(
|
|
| 802 |
else:
|
| 803 |
logging.error(f"[{sid}] Failed to decode uploaded document: {rfp_filename}")
|
| 804 |
|
| 805 |
-
if ctx
|
| 806 |
content_type, content_string = proposal_content.split(',')
|
| 807 |
decoded = base64.b64decode(content_string)
|
| 808 |
text = decode_document(decoded)
|
|
@@ -829,7 +828,7 @@ def unified_master_callback(
|
|
| 829 |
'recover-action-btn', 'board-action-btn', 'loe-action-btn'
|
| 830 |
]
|
| 831 |
|
| 832 |
-
if ctx
|
| 833 |
got_lock = sess_data["gemini_lock"].acquire(blocking=False)
|
| 834 |
if not got_lock:
|
| 835 |
output_data_upload = html.Div("Another Gemini operation is in progress. Please wait or cancel.", style={"wordWrap": "break-word"})
|
|
@@ -840,7 +839,7 @@ def unified_master_callback(
|
|
| 840 |
"expanded"
|
| 841 |
)
|
| 842 |
try:
|
| 843 |
-
triggered_id = ctx
|
| 844 |
if triggered_id == "shred-action-btn":
|
| 845 |
action_name = "shred"
|
| 846 |
result, generated_filename, generated_xlsx_bytes, _, _ = process_document(sess_data, action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, None)
|
|
|
|
| 2 |
import base64
|
| 3 |
import io
|
| 4 |
import dash
|
| 5 |
+
from dash import dcc, html, Input, Output, State, callback_context, ALL
|
| 6 |
import dash_bootstrap_components as dbc
|
| 7 |
import pandas as pd
|
| 8 |
import logging
|
|
|
|
| 679 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
| 680 |
uploaded_rfp_decoded_bytes = None
|
| 681 |
|
| 682 |
+
triggered_id = getattr(ctx, "triggered_id", None)
|
| 683 |
is_doc_delete = False
|
| 684 |
is_proposal_delete = False
|
| 685 |
doc_del_filename = None
|
| 686 |
proposal_del_filename = None
|
| 687 |
+
|
| 688 |
+
if isinstance(triggered_id, dict):
|
| 689 |
+
if triggered_id.get('type') == 'delete-doc-btn' and triggered_id.get('group') == 'doc':
|
| 690 |
+
is_doc_delete = True
|
| 691 |
+
doc_del_filename = triggered_id.get('index')
|
| 692 |
+
elif triggered_id.get('type') == 'delete-proposal-btn' and triggered_id.get('group') == 'proposal':
|
| 693 |
+
is_proposal_delete = True
|
| 694 |
+
proposal_del_filename = triggered_id.get('index')
|
|
|
|
| 695 |
|
| 696 |
if is_doc_delete and doc_del_filename:
|
| 697 |
if doc_del_filename in sess_data["uploaded_documents"]:
|
|
|
|
| 748 |
doc_delete_clicks = safe_get_n_clicks(ctx, 8)
|
| 749 |
proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
|
| 750 |
|
| 751 |
+
if not ctx.triggered or (getattr(ctx, "triggered_id", None) == 'session-id-store'):
|
| 752 |
doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
|
| 753 |
doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
|
| 754 |
proposal_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["proposals"].keys()]
|
|
|
|
| 762 |
"expanded"
|
| 763 |
)
|
| 764 |
|
| 765 |
+
if getattr(ctx, "triggered_id", None) == 'cancel-action-btn':
|
| 766 |
lock = sess_data.get("gemini_lock")
|
| 767 |
if lock and lock.locked():
|
| 768 |
try:
|
|
|
|
| 784 |
"expanded"
|
| 785 |
)
|
| 786 |
|
| 787 |
+
if getattr(ctx, "triggered_id", None) == 'upload-document' and rfp_content is not None and rfp_filename:
|
| 788 |
content_type, content_string = rfp_content.split(',')
|
| 789 |
decoded = base64.b64decode(content_string)
|
| 790 |
uploaded_rfp_decoded_bytes = decoded
|
|
|
|
| 801 |
else:
|
| 802 |
logging.error(f"[{sid}] Failed to decode uploaded document: {rfp_filename}")
|
| 803 |
|
| 804 |
+
if getattr(ctx, "triggered_id", None) == 'upload-proposal' and proposal_content is not None and proposal_filename:
|
| 805 |
content_type, content_string = proposal_content.split(',')
|
| 806 |
decoded = base64.b64decode(content_string)
|
| 807 |
text = decode_document(decoded)
|
|
|
|
| 828 |
'recover-action-btn', 'board-action-btn', 'loe-action-btn'
|
| 829 |
]
|
| 830 |
|
| 831 |
+
if getattr(ctx, "triggered_id", None) in action_btns:
|
| 832 |
got_lock = sess_data["gemini_lock"].acquire(blocking=False)
|
| 833 |
if not got_lock:
|
| 834 |
output_data_upload = html.Div("Another Gemini operation is in progress. Please wait or cancel.", style={"wordWrap": "break-word"})
|
|
|
|
| 839 |
"expanded"
|
| 840 |
)
|
| 841 |
try:
|
| 842 |
+
triggered_id = getattr(ctx, "triggered_id", None)
|
| 843 |
if triggered_id == "shred-action-btn":
|
| 844 |
action_name = "shred"
|
| 845 |
result, generated_filename, generated_xlsx_bytes, _, _ = process_document(sess_data, action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, None)
|