From 06359669e2f7c7cb2fcd45ac94ae9e2b52578bdf Mon Sep 17 00:00:00 2001 From: Cubix33 Date: Thu, 19 Mar 2026 20:07:54 +0000 Subject: [PATCH] #299- severity flagging with keywords --- src/filler.py | 20 +++++++++++++++----- src/llm.py | 12 +++++++++++- src/main.py | 7 ++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/filler.py b/src/filler.py index e31e535..b8bce88 100644 --- a/src/filler.py +++ b/src/filler.py @@ -12,18 +12,28 @@ def fill_form(self, pdf_form: str, llm: LLM): Fill a PDF form with values from user_input using LLM. Fields are filled in the visual order (top-to-bottom, left-to-right). """ + # Generate dictionary of answers from your original function + t2j = llm.main_loop() + textbox_answers = t2j.get_data() # This is a dictionary + + # --- NEW: SEVERITY FILENAME LOGIC --- + is_urgent = textbox_answers.get("SEVERITY_FLAG") == "HIGH" + prefix = "URGENT_" if is_urgent else "" + output_pdf = ( pdf_form[:-4] + "_" + + prefix + datetime.now().strftime("%Y%m%d_%H%M%S") + "_filled.pdf" ) - # Generate dictionary of answers from your original function - t2j = llm.main_loop() - textbox_answers = t2j.get_data() # This is a dictionary - - answers_list = list(textbox_answers.values()) + # Build answers_list, safely ignoring our internal SEVERITY_FLAG + answers_list = [] + for key, val in textbox_answers.items(): + if key != "SEVERITY_FLAG": + answers_list.append(val) + # ------------------------------------ # Read PDF pdf = PdfReader(pdf_form) diff --git a/src/llm.py b/src/llm.py index 70937f9..56dbd2e 100644 --- a/src/llm.py +++ b/src/llm.py @@ -45,8 +45,18 @@ def build_prompt(self, current_field): return prompt def main_loop(self): + # --- NEW: REAL-TIME SEVERITY SCAN --- + trigger_words = ["gun", "heart attack", "trapped", "hazmat", "cardiac", "shooter", "fire"] + transcript_lower = self._transcript_text.lower() + + for word in trigger_words: + if word in transcript_lower: + print(f"🚨 [URGENT]: High-severity keyword detected -> '{word}'") + self._json["SEVERITY_FLAG"] = "HIGH" + break + # ------------------------------------ # self.type_check_all() - for field in self._target_fields.keys(): + for field in self._target_fields: prompt = self.build_prompt(field) # print(prompt) # ollama_url = "http://localhost:11434/api/generate" diff --git a/src/main.py b/src/main.py index 5bb632b..adaadac 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,7 @@ from commonforms import prepare_form from pypdf import PdfReader from controller import Controller +from typing import Union def input_fields(num_fields: int): fields = [] @@ -67,8 +68,8 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio if __name__ == "__main__": file = "./src/inputs/file.pdf" - user_input = "Hi. The employee's name is John Doe. His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is , and the date is 01/02/2005" - fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"] + user_input = "Hi. The employee's name is John Doe. He was in a fire ! His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is , and the date is 01/02/2005" + descriptive_fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"] prepared_pdf = "temp_outfile.pdf" prepare_form(file, prepared_pdf) @@ -80,4 +81,4 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio num_fields = 0 controller = Controller() - controller.fill_form(user_input, fields, file) + controller.fill_form(user_input, descriptive_fields, file)