Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -150,7 +150,7 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
150 |
|
151 |
doc_content = None
|
152 |
doc_fileid = None
|
153 |
-
if action in ["shred", "compliance", "virtual_board", "proposal"]:
|
154 |
if selected_filename and selected_filename in uploaded_documents:
|
155 |
doc_content = uploaded_documents[selected_filename]
|
156 |
doc_fileid = uploaded_documents_fileid.get(selected_filename)
|
@@ -224,7 +224,6 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
224 |
return "No RFP/SOW/PWS/RFI document selected.", None, None, None, None
|
225 |
rfp_filename = selected_filename
|
226 |
rfp_fileid = uploaded_documents_fileid.get(selected_filename)
|
227 |
-
# Try to upload to Gemini if fileid missing and we have bytes
|
228 |
if not rfp_fileid and rfp_filename in uploaded_documents_bytes:
|
229 |
try:
|
230 |
fileid = upload_to_gemini_file(uploaded_documents_bytes[rfp_filename], rfp_filename)
|
@@ -255,7 +254,38 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
255 |
return result, None, None, None, None
|
256 |
|
257 |
elif action == 'recover':
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
elif action == 'loe':
|
260 |
return "LOE estimation not implemented yet.", None, None, None, None
|
261 |
return "Action not implemented yet.", None, None, None, None
|
@@ -608,15 +638,21 @@ def master_callback(
|
|
608 |
try:
|
609 |
if triggered_id == "proposal-action-btn":
|
610 |
action_name = "proposal"
|
|
|
|
|
|
|
|
|
|
|
611 |
elif triggered_id == "recover-action-btn":
|
612 |
action_name = "recover"
|
|
|
|
|
|
|
|
|
|
|
613 |
elif triggered_id == "loe-action-btn":
|
614 |
action_name = "loe"
|
615 |
-
|
616 |
-
action_name = None
|
617 |
-
# For proposal, always use the selected doc_value and its bytes if available
|
618 |
-
selected_bytes = uploaded_documents_bytes.get(doc_value, None)
|
619 |
-
if action_name:
|
620 |
result, _, _, generated_filename, generated_docx_bytes = process_document(
|
621 |
action_name, doc_value, chat_input, selected_bytes, None
|
622 |
)
|
|
|
150 |
|
151 |
doc_content = None
|
152 |
doc_fileid = None
|
153 |
+
if action in ["shred", "compliance", "virtual_board", "proposal", "recover"]:
|
154 |
if selected_filename and selected_filename in uploaded_documents:
|
155 |
doc_content = uploaded_documents[selected_filename]
|
156 |
doc_fileid = uploaded_documents_fileid.get(selected_filename)
|
|
|
224 |
return "No RFP/SOW/PWS/RFI document selected.", None, None, None, None
|
225 |
rfp_filename = selected_filename
|
226 |
rfp_fileid = uploaded_documents_fileid.get(selected_filename)
|
|
|
227 |
if not rfp_fileid and rfp_filename in uploaded_documents_bytes:
|
228 |
try:
|
229 |
fileid = upload_to_gemini_file(uploaded_documents_bytes[rfp_filename], rfp_filename)
|
|
|
254 |
return result, None, None, None, None
|
255 |
|
256 |
elif action == 'recover':
|
257 |
+
# For recover: need compliance check or shred (selected_filename), and proposal (selected_proposal_filename)
|
258 |
+
if not selected_proposal_filename or selected_proposal_filename not in proposals:
|
259 |
+
return "No proposal document selected for recovery.", None, None, None, None
|
260 |
+
if not selected_filename or selected_filename not in uploaded_documents:
|
261 |
+
return "No compliance check or shredded requirements document selected for recovery.", None, None, None, None
|
262 |
+
findings_content = uploaded_documents[selected_filename]
|
263 |
+
proposal_text = proposals[selected_proposal_filename]
|
264 |
+
logging.info(f"Recovery: fixing proposal [{selected_proposal_filename}] based on findings [{selected_filename}]")
|
265 |
+
prompt = (
|
266 |
+
"You are a proposal compliance recovery expert. Use the following findings and recommendations table, and the original proposal response. "
|
267 |
+
"Address ONLY those sections of the proposal that have a finding and a recommendation for improvement. "
|
268 |
+
"Do NOT change sections that are marked as fully compliant or already fully address the requirements. "
|
269 |
+
"For each section that needs fixing, revise it in the proposal to address the recommendation for compliance or to strengthen the response. "
|
270 |
+
"Return the full proposal with only the necessary sections revised, and leave all other sections untouched. "
|
271 |
+
"Do not add any introduction, summary, or comments. Return only the revised proposal in markdown, nothing else.\n\n"
|
272 |
+
"Findings and Recommendations Table or Requirements Table:\n"
|
273 |
+
f"{findings_content}\n"
|
274 |
+
"---\nOriginal Proposal:\n"
|
275 |
+
f"{proposal_text}\n"
|
276 |
+
)
|
277 |
+
result = gemini_generate_content(prompt, file_id=None, chat_input=chat_input)
|
278 |
+
if result and not result.startswith("Error"):
|
279 |
+
# Name for the recovered proposal: <original proposal base>_recovered.docx
|
280 |
+
base_name = os.path.splitext(selected_proposal_filename)[0]
|
281 |
+
recovered_docx_name = f"{base_name}_recovered.docx"
|
282 |
+
docx_bytes = save_proposal_as_docx(result, base_name)
|
283 |
+
proposals[recovered_docx_name] = result
|
284 |
+
proposals_fileid[recovered_docx_name] = None
|
285 |
+
return result, None, None, recovered_docx_name, docx_bytes
|
286 |
+
else:
|
287 |
+
return result, None, None, None, None
|
288 |
+
|
289 |
elif action == 'loe':
|
290 |
return "LOE estimation not implemented yet.", None, None, None, None
|
291 |
return "Action not implemented yet.", None, None, None, None
|
|
|
638 |
try:
|
639 |
if triggered_id == "proposal-action-btn":
|
640 |
action_name = "proposal"
|
641 |
+
selected_bytes = uploaded_documents_bytes.get(doc_value, None)
|
642 |
+
result, _, _, generated_filename, generated_docx_bytes = process_document(
|
643 |
+
action_name, doc_value, chat_input, selected_bytes, None
|
644 |
+
)
|
645 |
+
output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
|
646 |
elif triggered_id == "recover-action-btn":
|
647 |
action_name = "recover"
|
648 |
+
# For recover, use selected compliance/shred doc (doc_value) and selected proposal (proposal_value)
|
649 |
+
result, _, _, generated_filename, generated_docx_bytes = process_document(
|
650 |
+
action_name, doc_value, chat_input, None, proposal_value
|
651 |
+
)
|
652 |
+
output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
|
653 |
elif triggered_id == "loe-action-btn":
|
654 |
action_name = "loe"
|
655 |
+
selected_bytes = uploaded_documents_bytes.get(doc_value, None)
|
|
|
|
|
|
|
|
|
656 |
result, _, _, generated_filename, generated_docx_bytes = process_document(
|
657 |
action_name, doc_value, chat_input, selected_bytes, None
|
658 |
)
|