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

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +40 -2
app.py CHANGED
@@ -150,6 +150,16 @@ def save_compliance_as_docx(compliance_text, rfp_filename):
150
  memf.seek(0)
151
  return memf.read()
152
 
 
 
 
 
 
 
 
 
 
 
153
  def process_document(action, selected_filename=None, chat_input=None, rfp_decoded_bytes=None, selected_proposal_filename=None):
154
  global generated_response
155
 
@@ -224,7 +234,33 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
224
  return result, None, None, None, None
225
 
226
  elif action == 'virtual_board':
227
- return "Virtual board not implemented yet.", None, None, None, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
  elif action == 'proposal':
230
  if not doc_content:
@@ -623,7 +659,9 @@ def master_callback(
623
  output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
624
  elif triggered_id == "board-action-btn":
625
  action_name = "virtual_board"
626
- result, generated_filename, generated_docx_bytes, _, _ = process_document(action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, None)
 
 
627
  output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
628
  finally:
629
  gemini_lock.release()
 
150
  memf.seek(0)
151
  return memf.read()
152
 
153
+ def save_virtual_board_as_docx(board_text, base_filename):
154
+ doc = Document()
155
+ doc.add_heading(f"Evaluation Board for {base_filename}", 0)
156
+ for line in board_text.split('\n'):
157
+ doc.add_paragraph(line)
158
+ memf = io.BytesIO()
159
+ doc.save(memf)
160
+ memf.seek(0)
161
+ return memf.read()
162
+
163
  def process_document(action, selected_filename=None, chat_input=None, rfp_decoded_bytes=None, selected_proposal_filename=None):
164
  global generated_response
165
 
 
234
  return result, None, None, None, None
235
 
236
  elif action == 'virtual_board':
237
+ # Implementation for extracting evaluation criteria (L & M) and evaluating proposal
238
+ if not selected_proposal_filename or selected_proposal_filename not in proposals:
239
+ return "No proposal document selected for evaluation board.", None, None, None, None
240
+ if not selected_filename or selected_filename not in uploaded_documents:
241
+ return "No RFP/SOW/PWS/RFI document selected for evaluation board.", None, None, None, None
242
+
243
+ rfp_text = uploaded_documents[selected_filename]
244
+ proposal_text = proposals[selected_proposal_filename]
245
+ logging.info(f"Evaluation Board: extracting criteria from RFP [{selected_filename}], evaluating proposal [{selected_proposal_filename}]")
246
+ prompt = (
247
+ "You are a federal acquisition evaluation board. Read the following RFP/SOW/PWS/RFI and extract ONLY Section L and Section M (evaluation criteria). "
248
+ "Then, for each extracted evaluation criterion, evaluate the provided proposal and rate it as either: unacceptable, acceptable, good, or outstanding (no other ratings allowed). "
249
+ "Return ONLY a markdown spreadsheet/table (NO intro, NO outro, NO comments, NO summary) with exactly these columns: | Evaluation Criteria | Evaluation (unacceptable/acceptable/good/outstanding) |. "
250
+ "Each row should have: the criterion exactly as extracted from the document, and the evaluation for how well the proposal meets or exceeds it. Do not rewrite or omit any criterion. Only the table, nothing else.\n\n"
251
+ f"---\nRFP/SOW/PWS/RFI ({selected_filename}):\n{rfp_text}\n"
252
+ "---\nProposal Document:\n"
253
+ f"{proposal_text}\n"
254
+ )
255
+ result = gemini_generate_content(prompt, file_id=None, chat_input=None)
256
+ if result and not result.startswith("Error"):
257
+ docx_bytes = save_virtual_board_as_docx(result, selected_filename)
258
+ board_docx_name = f"{os.path.splitext(selected_filename)[0]}_evaluation_board.docx"
259
+ uploaded_documents[board_docx_name] = result
260
+ shredded_documents[board_docx_name] = docx_bytes
261
+ return result, board_docx_name, docx_bytes, None, None
262
+ else:
263
+ return result, None, None, None, None
264
 
265
  elif action == 'proposal':
266
  if not doc_content:
 
659
  output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
660
  elif triggered_id == "board-action-btn":
661
  action_name = "virtual_board"
662
+ result, generated_filename, generated_docx_bytes, _, _ = process_document(
663
+ action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, proposal_value
664
+ )
665
  output_data_upload = dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
666
  finally:
667
  gemini_lock.release()