From b0b5befdb1a7c775759779a5aaf8a1e8f3f16f4f Mon Sep 17 00:00:00 2001 From: Ankitha Madhyastha Date: Wed, 25 Feb 2026 21:08:36 +0530 Subject: [PATCH 1/4] feat: add context memory to reuse outputs across modules --- app.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 59d9534..b7ebd13 100644 --- a/app.py +++ b/app.py @@ -488,6 +488,18 @@ def calculate_confidence(result: dict): else: return "Low", "๐Ÿ”ด" + # ================= CONTEXT MEMORY ================= +if "context_memory" not in st.session_state: + st.session_state.context_memory = "" + +def store_context(text: str): + """Store text into reusable memory.""" + if text: + st.session_state.context_memory = text + +def clear_context(): + """Clear stored context.""" + st.session_state.context_memory = "" # reading the page url def _read_url_page(): try: @@ -792,6 +804,18 @@ def _read_url_page(): st.error(f"{confidence_icon} Low Confidence Mapping") st.write("###") + # ===== Context Memory Buttons ===== + col_ctx1, col_ctx2 = st.columns(2) + + with col_ctx1: + if st.button("๐Ÿ“ฅ Use in Fact Checker"): + store_context(f"IPC {ipc} mapped to {bns}. Notes: {notes}") + st.success("Stored in memory. Go to Fact Checker.") + + with col_ctx2: + if st.button("๐Ÿงน Clear Memory"): + clear_context() + st.info("Context cleared.") # --- STEP 3: Action Buttons --- col_a, col_b, col_c, col_d = st.columns(4) @@ -1015,6 +1039,12 @@ def _read_url_page(): st.success("โœ… Text extraction completed!") st.text_area("Extracted Text", extracted, height=300) + # Store OCR text in memory + store_context(extracted) + + if st.button("๐Ÿ“ฅ Use in Fact Checker"): + st.success("OCR text stored for reuse.") + copy_to_clipboard(extracted, "Copy OCR Text") # ================= RISK ANALYSIS ================= @@ -1204,9 +1234,11 @@ def clean_text_for_tts(text: str) -> str: with col1: # Bind the value to our session state so Voice Input auto-fills this box + default_question = st.session_state.get("context_memory", "") or st.session_state.get('fact_search_val', '') + user_question = st.text_input( "Question", - value=st.session_state.get('fact_search_val', ''), + value=default_question, placeholder="e.g., penalty for cheating?", label_visibility="collapsed" ) @@ -1222,6 +1254,21 @@ def clean_text_for_tts(text: str) -> str: with col3: verify_btn = st.button("๐Ÿ“– Verify", use_container_width=True) + + # ===== Show Context Memory ===== + if st.session_state.context_memory: + col_m1, col_m2 = st.columns(2) + + with col_m1: + st.info("๐Ÿ“Œ Using stored context") + + with col_m2: + if st.button("๐Ÿงน Clear Memory"): + clear_context() + st.rerun() + + with st.expander("๐Ÿ“Œ Stored Context"): + st.write(st.session_state.context_memory) # --- Process Audio Input --- audio_val = audio_dict['bytes'] if audio_dict else None From 0210041fbf5b501be2e2f5566f18752437afc3b6 Mon Sep 17 00:00:00 2001 From: AnkithaMadhyastha Date: Tue, 3 Mar 2026 17:36:20 +0530 Subject: [PATCH 2/4] Enhance question input and context memory display Updated the text input to use a default question from session state and added functionality to show and clear context memory. --- app/pages/fact_checker.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/pages/fact_checker.py b/app/pages/fact_checker.py index 8902caf..aee3221 100644 --- a/app/pages/fact_checker.py +++ b/app/pages/fact_checker.py @@ -54,9 +54,14 @@ def render_fact_checker_page(): with col1: # Bind the value to our session state so Voice Input auto-fills this box + default_question = ( + st.session_state.get("context_memory", "") + or st.session_state.get("fact_search_val", "") + ) + user_question = st.text_input( - "Question", - value=st.session_state.get('fact_search_val', ''), + "Question", + value=default_question, placeholder="e.g., penalty for cheating?", label_visibility="collapsed" ) @@ -104,7 +109,20 @@ def render_fact_checker_page(): st.session_state['fact_search_val'] = voice_query st.session_state['fact_auto_search'] = True st.rerun() - + # ===== Show Context Memory ===== + if st.session_state.get("context_memory"): + col_m1, col_m2 = st.columns(2) + + with col_m1: + st.info("๐Ÿ“Œ Using stored context") + + with col_m2: + if st.button("๐Ÿงน Clear Memory"): + st.session_state.context_memory = "" + st.rerun() + + with st.expander("๐Ÿ“Œ Stored Context"): + st.write(st.session_state.context_memory) # --- Auto-Search Trigger --- if st.session_state.get('fact_auto_search'): verify_btn = True From 8a12b0555850087cb193be1ba7286013981bd03f Mon Sep 17 00:00:00 2001 From: AnkithaMadhyastha Date: Tue, 3 Mar 2026 17:41:35 +0530 Subject: [PATCH 3/4] Implement context memory buttons Added buttons to use and clear context memory in the app. --- app/pages/mapper.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/pages/mapper.py b/app/pages/mapper.py index 5148307..4db0e03 100644 --- a/app/pages/mapper.py +++ b/app/pages/mapper.py @@ -190,6 +190,19 @@ def render_mapper_page(): st.write("###") + # ===== Context Memory Buttons ===== + col_ctx1, col_ctx2 = st.columns(2) + + with col_ctx1: + if st.button("๐Ÿ“ฅ Use in Fact Checker"): + st.session_state.context_memory = f"IPC {ipc} mapped to {bns}. Notes: {notes}" + st.success("Stored in memory. Go to Fact Checker.") + + with col_ctx2: + if st.button("๐Ÿงน Clear Memory"): + st.session_state.context_memory = "" + st.info("Context cleared.") + # --- STEP 3: Action Buttons --- col_a, col_b, col_c, col_d = st.columns(4) From a6ffa4027172af49f675906fb858f3fb6a869bbb Mon Sep 17 00:00:00 2001 From: AnkithaMadhyastha Date: Tue, 3 Mar 2026 17:42:40 +0530 Subject: [PATCH 4/4] Add button to use extracted text in Fact Checker --- app/pages/ocr.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/pages/ocr.py b/app/pages/ocr.py index 5d81662..a02261d 100644 --- a/app/pages/ocr.py +++ b/app/pages/ocr.py @@ -69,6 +69,9 @@ def render_ocr_page(): st.success("โœ… Text extraction completed!") st.text_area("Extracted Text", extracted, height=300) + if st.button("๐Ÿ“ฅ Use in Fact Checker"): + st.session_state.context_memory = extracted + st.success("OCR text stored for reuse.") copy_to_clipboard(extracted, "Copy OCR Text") @@ -174,4 +177,4 @@ def render_ocr_page(): st.warning("โš  AI Engine failed to generate summary.") except Exception as e: - st.error(f"โŒ Error during processing: {str(e)}") \ No newline at end of file + st.error(f"โŒ Error during processing: {str(e)}")