bluenevus commited on
Commit
f5c0c7e
·
1 Parent(s): b48ac61

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +5 -41
app.py CHANGED
@@ -181,6 +181,7 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
181
  if chat_input:
182
  prompt += f"User additional instructions: {chat_input}\n"
183
  prompt += f"\nFile Name: {selected_filename}\n\n"
 
184
  result = gemini_generate_content(prompt, file_id=doc_fileid, chat_input=chat_input)
185
  if result and not result.startswith("Error"):
186
  docx_bytes = save_shredded_as_docx(result, selected_filename)
@@ -270,41 +271,8 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
270
 
271
  findings_content = uploaded_documents[selected_filename]
272
  proposal_text = proposals[selected_proposal_filename]
273
- findings_fileid = uploaded_documents_fileid.get(selected_filename)
274
- proposal_fileid = proposals_fileid.get(selected_proposal_filename)
275
-
276
- # Ensure both findings and proposal are uploaded as files in Gemini
277
- if not findings_fileid:
278
- findings_bytes = None
279
- if selected_filename in shredded_documents:
280
- findings_bytes = shredded_documents[selected_filename]
281
- elif selected_filename in uploaded_documents_bytes:
282
- findings_bytes = uploaded_documents_bytes[selected_filename]
283
- else:
284
- findings_bytes = save_compliance_as_docx(findings_content, selected_filename)
285
- if findings_bytes:
286
- try:
287
- findings_fileid = upload_to_gemini_file(findings_bytes, selected_filename)
288
- if findings_fileid:
289
- uploaded_documents_fileid[selected_filename] = findings_fileid
290
- logging.info(f"Findings/Compliance doc {selected_filename} uploaded to Gemini for recover.")
291
- except Exception as e:
292
- logging.error(f"Failed to upload findings doc {selected_filename} for recover: {e}")
293
-
294
- if not proposal_fileid:
295
- proposal_bytes = save_proposal_as_docx(proposals[selected_proposal_filename], selected_proposal_filename)
296
- if proposal_bytes:
297
- try:
298
- proposal_fileid = upload_to_gemini_file(proposal_bytes, selected_proposal_filename)
299
- if proposal_fileid:
300
- proposals_fileid[selected_proposal_filename] = proposal_fileid
301
- logging.info(f"Proposal doc {selected_proposal_filename} uploaded to Gemini for recover.")
302
- except Exception as e:
303
- logging.error(f"Failed to upload proposal doc {selected_proposal_filename} for recover: {e}")
304
-
305
- logging.info(f"Recovery: fixing proposal [{selected_proposal_filename}] based on findings [{selected_filename}]")
306
  prompt = (
307
- "You are a proposal compliance recovery expert. Use the findings and recommendations table and the original proposal response provided in the attached files. "
308
  "Address ONLY those sections of the proposal that have a finding and a recommendation for improvement. "
309
  "Do NOT change sections that are marked as fully compliant or already fully address the requirements. "
310
  "For each section that needs fixing, revise it in the proposal to address the recommendation for compliance or to strengthen the response. "
@@ -314,14 +282,10 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
314
  if chat_input:
315
  prompt += f"User additional instructions: {chat_input}\n"
316
 
317
- # Compose file_ids and pass both files to Gemini in order
318
- file_ids = []
319
- if findings_fileid:
320
- file_ids.append(findings_fileid)
321
- if proposal_fileid:
322
- file_ids.append(proposal_fileid)
323
 
324
- result = gemini_generate_content(prompt, file_ids=file_ids)
325
  if result and not result.startswith("Error"):
326
  base_name = os.path.splitext(selected_proposal_filename)[0]
327
  recovered_docx_name = f"{base_name}_recovered.docx"
 
181
  if chat_input:
182
  prompt += f"User additional instructions: {chat_input}\n"
183
  prompt += f"\nFile Name: {selected_filename}\n\n"
184
+ prompt += doc_content
185
  result = gemini_generate_content(prompt, file_id=doc_fileid, chat_input=chat_input)
186
  if result and not result.startswith("Error"):
187
  docx_bytes = save_shredded_as_docx(result, selected_filename)
 
271
 
272
  findings_content = uploaded_documents[selected_filename]
273
  proposal_text = proposals[selected_proposal_filename]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  prompt = (
275
+ "You are a proposal compliance recovery expert. Use the findings and recommendations table and the original proposal response provided below. "
276
  "Address ONLY those sections of the proposal that have a finding and a recommendation for improvement. "
277
  "Do NOT change sections that are marked as fully compliant or already fully address the requirements. "
278
  "For each section that needs fixing, revise it in the proposal to address the recommendation for compliance or to strengthen the response. "
 
282
  if chat_input:
283
  prompt += f"User additional instructions: {chat_input}\n"
284
 
285
+ prompt += f"\n---\nFindings and Recommendations Table ({selected_filename}):\n{findings_content}\n"
286
+ prompt += f"\n---\nOriginal Proposal Document ({selected_proposal_filename}):\n{proposal_text}\n"
 
 
 
 
287
 
288
+ result = gemini_generate_content(prompt, file_id=None, chat_input=chat_input)
289
  if result and not result.startswith("Error"):
290
  base_name = os.path.splitext(selected_proposal_filename)[0]
291
  recovered_docx_name = f"{base_name}_recovered.docx"