Update pages/facebook_extractor.py
Browse files- pages/facebook_extractor.py +13 -2
pages/facebook_extractor.py
CHANGED
|
@@ -579,7 +579,7 @@ def main():
|
|
| 579 |
if st.button("β Back to Main Dashboard"):
|
| 580 |
st.switch_page("app.py")
|
| 581 |
|
| 582 |
-
# Initialize session state
|
| 583 |
if "extractor" not in st.session_state:
|
| 584 |
st.session_state.extractor = FacebookDataSimulator()
|
| 585 |
if "facebook_data" not in st.session_state:
|
|
@@ -592,6 +592,8 @@ def main():
|
|
| 592 |
st.session_state.chat_history = []
|
| 593 |
if "processing_mode" not in st.session_state:
|
| 594 |
st.session_state.processing_mode = "ai" # ai or simple
|
|
|
|
|
|
|
| 595 |
|
| 596 |
# Sidebar
|
| 597 |
with st.sidebar:
|
|
@@ -653,14 +655,17 @@ def main():
|
|
| 653 |
st.session_state.vectorstore = result[0]
|
| 654 |
st.session_state.chatbot = create_chatbot(result[0])
|
| 655 |
st.session_state.chat_history = []
|
|
|
|
| 656 |
st.success("β
AI analysis ready!")
|
| 657 |
else:
|
| 658 |
st.warning("β οΈ Using simple analysis (AI features limited)")
|
| 659 |
st.session_state.chatbot = "simple"
|
| 660 |
st.session_state.chat_history = []
|
|
|
|
| 661 |
else:
|
| 662 |
st.session_state.chatbot = "simple"
|
| 663 |
st.session_state.chat_history = []
|
|
|
|
| 664 |
st.success("β
Simple analysis ready!")
|
| 665 |
|
| 666 |
source = extracted_data.get('source', 'unknown')
|
|
@@ -679,6 +684,7 @@ def main():
|
|
| 679 |
st.session_state.vectorstore = None
|
| 680 |
st.session_state.chatbot = None
|
| 681 |
st.session_state.chat_history = []
|
|
|
|
| 682 |
st.rerun()
|
| 683 |
|
| 684 |
# Main content - RESTRUCTURED LAYOUT
|
|
@@ -792,7 +798,12 @@ def main():
|
|
| 792 |
if st.session_state.chatbot and st.session_state.facebook_data:
|
| 793 |
user_input = st.chat_input("Ask about the Facebook data...")
|
| 794 |
|
| 795 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 797 |
|
| 798 |
with st.spinner("π€ Analyzing..."):
|
|
|
|
| 579 |
if st.button("β Back to Main Dashboard"):
|
| 580 |
st.switch_page("app.py")
|
| 581 |
|
| 582 |
+
# Initialize session state - WITH DUPLICATION PROTECTION
|
| 583 |
if "extractor" not in st.session_state:
|
| 584 |
st.session_state.extractor = FacebookDataSimulator()
|
| 585 |
if "facebook_data" not in st.session_state:
|
|
|
|
| 592 |
st.session_state.chat_history = []
|
| 593 |
if "processing_mode" not in st.session_state:
|
| 594 |
st.session_state.processing_mode = "ai" # ai or simple
|
| 595 |
+
if "last_user_input" not in st.session_state:
|
| 596 |
+
st.session_state.last_user_input = "" # ADDED: Prevent duplication
|
| 597 |
|
| 598 |
# Sidebar
|
| 599 |
with st.sidebar:
|
|
|
|
| 655 |
st.session_state.vectorstore = result[0]
|
| 656 |
st.session_state.chatbot = create_chatbot(result[0])
|
| 657 |
st.session_state.chat_history = []
|
| 658 |
+
st.session_state.last_user_input = "" # Reset
|
| 659 |
st.success("β
AI analysis ready!")
|
| 660 |
else:
|
| 661 |
st.warning("β οΈ Using simple analysis (AI features limited)")
|
| 662 |
st.session_state.chatbot = "simple"
|
| 663 |
st.session_state.chat_history = []
|
| 664 |
+
st.session_state.last_user_input = "" # Reset
|
| 665 |
else:
|
| 666 |
st.session_state.chatbot = "simple"
|
| 667 |
st.session_state.chat_history = []
|
| 668 |
+
st.session_state.last_user_input = "" # Reset
|
| 669 |
st.success("β
Simple analysis ready!")
|
| 670 |
|
| 671 |
source = extracted_data.get('source', 'unknown')
|
|
|
|
| 684 |
st.session_state.vectorstore = None
|
| 685 |
st.session_state.chatbot = None
|
| 686 |
st.session_state.chat_history = []
|
| 687 |
+
st.session_state.last_user_input = ""
|
| 688 |
st.rerun()
|
| 689 |
|
| 690 |
# Main content - RESTRUCTURED LAYOUT
|
|
|
|
| 798 |
if st.session_state.chatbot and st.session_state.facebook_data:
|
| 799 |
user_input = st.chat_input("Ask about the Facebook data...")
|
| 800 |
|
| 801 |
+
# ADDED: Duplication protection
|
| 802 |
+
if user_input and user_input != st.session_state.last_user_input:
|
| 803 |
+
# Store current input to prevent duplication
|
| 804 |
+
st.session_state.last_user_input = user_input
|
| 805 |
+
|
| 806 |
+
# Add user message
|
| 807 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 808 |
|
| 809 |
with st.spinner("π€ Analyzing..."):
|