Refat81 commited on
Commit
0ba1440
Β·
verified Β·
1 Parent(s): d395d4e

Update pages/facebook_extractor.py

Browse files
Files changed (1) hide show
  1. pages/facebook_extractor.py +124 -123
pages/facebook_extractor.py CHANGED
@@ -681,135 +681,136 @@ def main():
681
  st.session_state.chat_history = []
682
  st.rerun()
683
 
684
- # Main content
685
- col1, col2 = st.columns([1, 1])
686
 
687
- with col1:
688
- st.header("πŸ“Š Extraction Results")
689
-
690
- if st.session_state.facebook_data:
691
- data = st.session_state.facebook_data
692
- page_info = data['page_info']
693
- content_blocks = data['content_blocks']
694
- source = data.get('source', 'unknown')
695
-
696
- if source == 'demo':
697
- st.warning("πŸ“ **Demo Data** - Realistic simulation (Facebook restrictions)")
698
- else:
699
- st.success("βœ… **Real Data** - Successfully extracted")
700
-
701
- # Show processing mode
702
- if st.session_state.processing_mode == "simple":
703
- st.info("πŸ”§ **Simple Analysis Mode** - Rule-based processing")
704
- else:
705
- st.info("πŸ€– **AI Analysis Mode** - Embedding-based processing")
706
-
707
- # Metrics
708
- col1, col2, col3 = st.columns(3)
709
- with col1:
710
- st.metric("Content Blocks", len(content_blocks))
711
- with col2:
712
- st.metric("Data Source", source.upper())
713
- with col3:
714
- st.metric("Analysis Mode", "AI" if st.session_state.processing_mode == "ai" else "Simple")
715
-
716
- # Page info
717
- st.subheader("🏷️ Page Information")
718
- st.write(f"**Title:** {page_info['title']}")
719
- st.write(f"**URL Type:** {data['url_type']}")
720
- st.write(f"**Description:** {page_info.get('description', 'No description')}")
721
-
722
- if page_info.get('member_count'):
723
- st.write(f"**Members:** {page_info['member_count']}")
724
- elif page_info.get('follower_count'):
725
- st.write(f"**Followers:** {page_info['follower_count']}")
726
-
727
- st.write(f"**Access:** {page_info.get('access_note', 'Public content')}")
728
-
729
- # Content samples
730
- st.subheader("πŸ“ Content Analysis")
731
- for i, block in enumerate(content_blocks):
732
- with st.expander(f"Content {i+1} - {block['content_type']} ({block['word_count']} words)"):
733
- st.write(block['content'])
734
- st.caption(f"Public: {block['is_public_content']}")
735
 
 
 
 
736
  else:
737
- st.info("""
738
- ## πŸ“˜ Facebook Data Extractor
739
-
740
- **University Project Feature**
741
-
742
- **How it works:**
743
- 1. Enter any Facebook URL
744
- 2. System tries real data extraction
745
- 3. If blocked, uses **realistic demo data**
746
- 4. Choose between AI or Simple analysis
747
-
748
- **Analysis Modes:**
749
- - πŸ€– **AI Analysis**: Uses embeddings and Mistral AI
750
- - πŸ”§ **Simple Analysis**: Rule-based (works without embeddings)
751
-
752
- **Perfect for demonstrating:**
753
- - Social media data extraction concepts
754
- - AI analysis capabilities
755
- - Platform integration
756
- - Error handling strategies
757
- """)
 
 
 
 
 
 
 
 
 
758
 
759
- with col2:
760
- st.header("πŸ’¬ Analysis Chat")
761
-
762
- if st.session_state.chatbot and st.session_state.facebook_data:
763
- # Display chat history
764
- for chat in st.session_state.chat_history:
765
- if chat["role"] == "user":
766
- with st.chat_message("user"):
767
- st.write(chat['content'])
768
- elif chat["role"] == "assistant":
769
- with st.chat_message("assistant"):
770
- st.write(chat['content'])
771
-
772
- # Chat input
773
- user_input = st.chat_input("Ask about the Facebook data...")
774
-
775
- if user_input:
776
- st.session_state.chat_history.append({"role": "user", "content": user_input})
777
-
778
- with st.spinner("πŸ€” Analyzing..."):
779
- try:
780
- if st.session_state.chatbot == "simple":
781
- # Use simple analysis
782
- response = simple_chat_analysis(user_input, st.session_state.facebook_data)
783
- st.session_state.chat_history.append({"role": "assistant", "content": response})
784
- else:
785
- # Use AI chatbot
786
- response = st.session_state.chatbot.invoke({"question": user_input})
787
- answer = response.get("answer", "I couldn't generate a response.")
788
- st.session_state.chat_history.append({"role": "assistant", "content": answer})
789
- st.rerun()
790
- except Exception as e:
791
- error_msg = f"Analysis Error: {str(e)}"
792
- st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
793
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
794
 
795
- # Suggested questions
796
- if not st.session_state.chat_history:
797
- st.subheader("πŸ’‘ Try asking:")
798
- suggestions = [
799
- "What is this Facebook group/page about?",
800
- "Summarize the main content and purpose",
801
- "What kind of community is this?",
802
- "Analyze the engagement and activity level"
803
- ]
804
-
805
- for suggestion in suggestions:
806
- if st.button(suggestion, key=f"fb_suggest_{suggestion}"):
807
- st.info(f"Type: '{suggestion}' in chat")
 
808
 
809
- elif st.session_state.facebook_data:
810
- st.info("πŸ’¬ Start chatting about the Facebook data")
811
- else:
812
- st.info("πŸ” Extract Facebook data to enable analysis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813
 
814
  if __name__ == "__main__":
815
  main()
 
681
  st.session_state.chat_history = []
682
  st.rerun()
683
 
684
+ # Main content - RESTRUCTURED LAYOUT
685
+ st.header("πŸ“Š Extraction Results")
686
 
687
+ if st.session_state.facebook_data:
688
+ data = st.session_state.facebook_data
689
+ page_info = data['page_info']
690
+ content_blocks = data['content_blocks']
691
+ source = data.get('source', 'unknown')
692
+
693
+ if source == 'demo':
694
+ st.warning("πŸ“ **Demo Data** - Realistic simulation (Facebook restrictions)")
695
+ else:
696
+ st.success("βœ… **Real Data** - Successfully extracted")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
 
698
+ # Show processing mode
699
+ if st.session_state.processing_mode == "simple":
700
+ st.info("πŸ”§ **Simple Analysis Mode** - Rule-based processing")
701
  else:
702
+ st.info("πŸ€– **AI Analysis Mode** - Embedding-based processing")
703
+
704
+ # Metrics
705
+ col1, col2, col3 = st.columns(3)
706
+ with col1:
707
+ st.metric("Content Blocks", len(content_blocks))
708
+ with col2:
709
+ st.metric("Data Source", source.upper())
710
+ with col3:
711
+ st.metric("Analysis Mode", "AI" if st.session_state.processing_mode == "ai" else "Simple")
712
+
713
+ # Page info
714
+ st.subheader("🏷️ Page Information")
715
+ st.write(f"**Title:** {page_info['title']}")
716
+ st.write(f"**URL Type:** {data['url_type']}")
717
+ st.write(f"**Description:** {page_info.get('description', 'No description')}")
718
+
719
+ if page_info.get('member_count'):
720
+ st.write(f"**Members:** {page_info['member_count']}")
721
+ elif page_info.get('follower_count'):
722
+ st.write(f"**Followers:** {page_info['follower_count']}")
723
+
724
+ st.write(f"**Access:** {page_info.get('access_note', 'Public content')}")
725
+
726
+ # Content samples
727
+ st.subheader("πŸ“ Content Analysis")
728
+ for i, block in enumerate(content_blocks):
729
+ with st.expander(f"Content {i+1} - {block['content_type']} ({block['word_count']} words)"):
730
+ st.write(block['content'])
731
+ st.caption(f"Public: {block['is_public_content']}")
732
 
733
+ else:
734
+ st.info("""
735
+ ## πŸ“˜ Facebook Data Extractor
736
+
737
+ **University Project Feature**
738
+
739
+ **How it works:**
740
+ 1. Enter any Facebook URL
741
+ 2. System tries real data extraction
742
+ 3. If blocked, uses **realistic demo data**
743
+ 4. Choose between AI or Simple analysis
744
+
745
+ **Analysis Modes:**
746
+ - πŸ€– **AI Analysis**: Uses embeddings and Mistral AI
747
+ - πŸ”§ **Simple Analysis**: Rule-based (works without embeddings)
748
+
749
+ **Perfect for demonstrating:**
750
+ - Social media data extraction concepts
751
+ - AI analysis capabilities
752
+ - Platform integration
753
+ - Error handling strategies
754
+ """)
755
+
756
+ # Chat section - SEPARATE from main content
757
+ st.markdown("---")
758
+ st.header("πŸ’¬ Analysis Chat")
759
+
760
+ if st.session_state.chatbot and st.session_state.facebook_data:
761
+ # Display chat history
762
+ for chat in st.session_state.chat_history:
763
+ if chat["role"] == "user":
764
+ with st.chat_message("user"):
765
+ st.write(chat['content'])
766
+ elif chat["role"] == "assistant":
767
+ with st.chat_message("assistant"):
768
+ st.write(chat['content'])
769
+
770
+ # Suggested questions when no history
771
+ if not st.session_state.chat_history:
772
+ st.subheader("πŸ’‘ Try asking:")
773
+ suggestions = [
774
+ "What is this Facebook group/page about?",
775
+ "Summarize the main content and purpose",
776
+ "What kind of community is this?",
777
+ "Analyze the engagement and activity level"
778
+ ]
779
 
780
+ cols = st.columns(len(suggestions))
781
+ for i, suggestion in enumerate(suggestions):
782
+ with cols[i]:
783
+ if st.button(suggestion, key=f"fb_suggest_{suggestion}", use_container_width=True):
784
+ st.info(f"Type: '{suggestion}' in the chat below")
785
+
786
+ elif st.session_state.facebook_data:
787
+ st.info("πŸ’¬ Start chatting about the Facebook data")
788
+ else:
789
+ st.info("πŸ” Extract Facebook data to enable analysis")
790
+
791
+ # CHAT INPUT - AT THE VERY BOTTOM, OUTSIDE ALL CONTAINERS
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
+ if user_input:
796
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
797
+
798
+ with st.spinner("πŸ€” Analyzing..."):
799
+ try:
800
+ if st.session_state.chatbot == "simple":
801
+ # Use simple analysis
802
+ response = simple_chat_analysis(user_input, st.session_state.facebook_data)
803
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
804
+ else:
805
+ # Use AI chatbot
806
+ response = st.session_state.chatbot.invoke({"question": user_input})
807
+ answer = response.get("answer", "I couldn't generate a response.")
808
+ st.session_state.chat_history.append({"role": "assistant", "content": answer})
809
+ st.rerun()
810
+ except Exception as e:
811
+ error_msg = f"Analysis Error: {str(e)}"
812
+ st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
813
+ st.rerun()
814
 
815
  if __name__ == "__main__":
816
  main()