Refat81 commited on
Commit
9e94e12
Β·
verified Β·
1 Parent(s): 0a67fcb

Update pages/linkedin_extractor.py

Browse files
Files changed (1) hide show
  1. pages/linkedin_extractor.py +107 -101
pages/linkedin_extractor.py CHANGED
@@ -459,34 +459,36 @@ def main():
459
  st.write("Chatbot Type:", "simple" if st.session_state.chatbot == "simple" else type(st.session_state.chatbot).__name__ if st.session_state.chatbot else "None")
460
  st.write("Chat History Length:", len(st.session_state.chat_history))
461
  st.write("Processing:", st.session_state.processing)
 
 
 
 
462
 
463
- # Main content area
464
- col1, col2 = st.columns([1, 1])
465
 
466
- with col1:
467
- st.markdown("### πŸ“Š Extraction Results")
 
 
468
 
469
- if st.session_state.processing:
470
- st.info("πŸ”„ Processing LinkedIn data...")
471
 
472
- elif st.session_state.extracted_data:
473
- data = st.session_state.extracted_data
474
- page_info = data['page_info']
475
- content_blocks = data['content_blocks']
476
-
477
- st.success("βœ… Extraction Complete")
478
-
479
- # Display metrics
480
- display_metrics(data)
481
-
482
- # Display page info
483
  st.markdown("#### 🏷️ Page Information")
484
  st.write(f"**Title:** {page_info['title']}")
485
  st.write(f"**URL:** {page_info['url']}")
486
  st.write(f"**Data Type:** {data['data_type'].title()}")
487
  st.write(f"**Content Blocks:** {len(content_blocks)}")
488
  st.write(f"**Extraction Time:** {data['extraction_time']}")
489
-
 
490
  # Display sample content
491
  st.markdown("#### πŸ“ Sample Content")
492
  for i, block in enumerate(content_blocks[:3]):
@@ -495,94 +497,98 @@ def main():
495
 
496
  if len(content_blocks) > 3:
497
  st.info(f"πŸ“„ And {len(content_blocks) - 3} more content blocks...")
498
-
499
- else:
500
- st.info("""
501
- πŸ‘‹ **Welcome to LinkedIn AI Analyzer!**
502
-
503
- **To get started:**
504
- 1. Select content type
505
- 2. Enter a LinkedIn URL or click a suggested company
506
- 3. Click "Extract & Analyze"
507
- 4. Chat with AI about the extracted content
508
-
509
- **Supported URLs:**
510
- - πŸ‘€ Public Profiles
511
- - 🏒 Company Pages
512
- - πŸ“ Public Posts
513
-
514
- **Features:**
515
- - Content extraction
516
- - Basic analysis
517
- - Interactive chat
518
- - Data insights
519
- """)
520
 
521
- with col2:
522
- st.markdown("### πŸ’¬ AI Chat Analysis")
523
-
524
- has_extracted_data = st.session_state.extracted_data and st.session_state.extracted_data.get("status") == "success"
525
-
526
- if has_extracted_data:
527
- st.success("πŸ’¬ Chat ready! Ask questions about the LinkedIn data.")
528
-
529
- # Display chat history
530
- for chat in st.session_state.chat_history:
531
- if chat["role"] == "user":
532
- with st.chat_message("user"):
533
- st.write(chat['content'])
534
- elif chat["role"] == "assistant":
535
- with st.chat_message("assistant"):
536
- st.write(chat['content'])
537
-
538
- # Chat input
539
- user_input = st.chat_input("Ask about the LinkedIn data...")
540
-
541
- if user_input:
542
- # Add user message to history
543
- st.session_state.chat_history.append({"role": "user", "content": user_input})
544
-
545
- # Generate response based on available capabilities
546
- if st.session_state.chatbot == "simple" or st.session_state.chatbot is None:
547
- # Use simple analysis
548
- with st.spinner("πŸ€” Analyzing..."):
549
- response = simple_chat_analysis(user_input, st.session_state.extracted_data)
550
- st.session_state.chat_history.append({"role": "assistant", "content": response})
551
- st.rerun()
552
- else:
553
- # Use AI chatbot
554
- with st.spinner("πŸ€” AI is analyzing..."):
555
- try:
556
- response = st.session_state.chatbot.invoke({"question": user_input})
557
- answer = response.get("answer", "I couldn't generate a response based on the available data.")
558
- st.session_state.chat_history.append({"role": "assistant", "content": answer})
559
- st.rerun()
560
- except Exception as e:
561
- error_msg = f"❌ AI Error: {str(e)}. Using simple analysis."
562
- simple_response = simple_chat_analysis(user_input, st.session_state.extracted_data)
563
- st.session_state.chat_history.append({"role": "assistant", "content": f"{error_msg}\n\n{simple_response}"})
564
- st.rerun()
 
 
 
 
 
 
565
 
566
- # Suggested questions
567
- if len(st.session_state.chat_history) == 0:
568
- st.markdown("#### πŸ’‘ Try asking:")
569
- suggestions = [
570
- "Summarize the main information",
571
- "What are the key highlights?",
572
- "Analyze the professional focus",
573
- "What insights can you extract?",
574
- "Tell me about the experience"
575
- ]
576
-
577
- for suggestion in suggestions:
578
  if st.button(suggestion, key=f"suggest_{suggestion}", use_container_width=True):
579
  st.info(f"πŸ’‘ Type in chat: '{suggestion}'")
 
 
 
 
 
 
 
 
 
 
580
 
581
- elif st.session_state.processing:
582
- st.info("πŸ”„ Extracting and processing LinkedIn data...")
583
-
584
- else:
585
- st.info("πŸ” Extract LinkedIn data to enable analysis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
 
587
  # Features section
588
  st.markdown("---")
 
459
  st.write("Chatbot Type:", "simple" if st.session_state.chatbot == "simple" else type(st.session_state.chatbot).__name__ if st.session_state.chatbot else "None")
460
  st.write("Chat History Length:", len(st.session_state.chat_history))
461
  st.write("Processing:", st.session_state.processing)
462
+
463
+ # Main content area - RESTRUCTURED LAYOUT
464
+ # First show extraction results
465
+ st.markdown("### πŸ“Š Extraction Results")
466
 
467
+ if st.session_state.processing:
468
+ st.info("πŸ”„ Processing LinkedIn data...")
469
 
470
+ elif st.session_state.extracted_data:
471
+ data = st.session_state.extracted_data
472
+ page_info = data['page_info']
473
+ content_blocks = data['content_blocks']
474
 
475
+ st.success("βœ… Extraction Complete")
 
476
 
477
+ # Display metrics
478
+ display_metrics(data)
479
+
480
+ # Display page info
481
+ col1, col2 = st.columns(2)
482
+
483
+ with col1:
 
 
 
 
484
  st.markdown("#### 🏷️ Page Information")
485
  st.write(f"**Title:** {page_info['title']}")
486
  st.write(f"**URL:** {page_info['url']}")
487
  st.write(f"**Data Type:** {data['data_type'].title()}")
488
  st.write(f"**Content Blocks:** {len(content_blocks)}")
489
  st.write(f"**Extraction Time:** {data['extraction_time']}")
490
+
491
+ with col2:
492
  # Display sample content
493
  st.markdown("#### πŸ“ Sample Content")
494
  for i, block in enumerate(content_blocks[:3]):
 
497
 
498
  if len(content_blocks) > 3:
499
  st.info(f"πŸ“„ And {len(content_blocks) - 3} more content blocks...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
 
501
+ else:
502
+ st.info("""
503
+ πŸ‘‹ **Welcome to LinkedIn AI Analyzer!**
504
+
505
+ **To get started:**
506
+ 1. Select content type
507
+ 2. Enter a LinkedIn URL or click a suggested company
508
+ 3. Click "Extract & Analyze"
509
+ 4. Chat with AI about the extracted content
510
+
511
+ **Supported URLs:**
512
+ - πŸ‘€ Public Profiles
513
+ - 🏒 Company Pages
514
+ - πŸ“ Public Posts
515
+
516
+ **Features:**
517
+ - Content extraction
518
+ - Basic analysis
519
+ - Interactive chat
520
+ - Data insights
521
+ """)
522
+
523
+ # Chat section - OUTSIDE of columns
524
+ st.markdown("---")
525
+ st.markdown("### πŸ’¬ AI Chat Analysis")
526
+
527
+ has_extracted_data = st.session_state.extracted_data and st.session_state.extracted_data.get("status") == "success"
528
+
529
+ if has_extracted_data:
530
+ st.success("πŸ’¬ Chat ready! Ask questions about the LinkedIn data.")
531
+
532
+ # Display chat history
533
+ for chat in st.session_state.chat_history:
534
+ if chat["role"] == "user":
535
+ with st.chat_message("user"):
536
+ st.write(chat['content'])
537
+ elif chat["role"] == "assistant":
538
+ with st.chat_message("assistant"):
539
+ st.write(chat['content'])
540
+
541
+ # Suggested questions - only show when no chat history
542
+ if len(st.session_state.chat_history) == 0:
543
+ st.markdown("#### πŸ’‘ Try asking:")
544
+ suggestions = [
545
+ "Summarize the main information",
546
+ "What are the key highlights?",
547
+ "Analyze the professional focus",
548
+ "What insights can you extract?",
549
+ "Tell me about the experience"
550
+ ]
551
 
552
+ cols = st.columns(len(suggestions))
553
+ for i, suggestion in enumerate(suggestions):
554
+ with cols[i]:
 
 
 
 
 
 
 
 
 
555
  if st.button(suggestion, key=f"suggest_{suggestion}", use_container_width=True):
556
  st.info(f"πŸ’‘ Type in chat: '{suggestion}'")
557
+
558
+ elif st.session_state.processing:
559
+ st.info("πŸ”„ Extracting and processing LinkedIn data...")
560
+
561
+ else:
562
+ st.info("πŸ” Extract LinkedIn data to enable analysis")
563
+
564
+ # CHAT INPUT - MUST BE AT THE BOTTOM, OUTSIDE ANY CONTAINERS
565
+ if has_extracted_data:
566
+ user_input = st.chat_input("Ask about the LinkedIn data...")
567
 
568
+ if user_input:
569
+ # Add user message to history
570
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
571
+
572
+ # Generate response based on available capabilities
573
+ if st.session_state.chatbot == "simple" or st.session_state.chatbot is None:
574
+ # Use simple analysis
575
+ with st.spinner("πŸ€” Analyzing..."):
576
+ response = simple_chat_analysis(user_input, st.session_state.extracted_data)
577
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
578
+ st.rerun()
579
+ else:
580
+ # Use AI chatbot
581
+ with st.spinner("πŸ€” AI is analyzing..."):
582
+ try:
583
+ response = st.session_state.chatbot.invoke({"question": user_input})
584
+ answer = response.get("answer", "I couldn't generate a response based on the available data.")
585
+ st.session_state.chat_history.append({"role": "assistant", "content": answer})
586
+ st.rerun()
587
+ except Exception as e:
588
+ error_msg = f"❌ AI Error: {str(e)}. Using simple analysis."
589
+ simple_response = simple_chat_analysis(user_input, st.session_state.extracted_data)
590
+ st.session_state.chat_history.append({"role": "assistant", "content": f"{error_msg}\n\n{simple_response}"})
591
+ st.rerun()
592
 
593
  # Features section
594
  st.markdown("---")