Refat81 commited on
Commit
41fbdb3
Β·
verified Β·
1 Parent(s): 268a97c

Update pages/linkedin_extractor.py

Browse files
Files changed (1) hide show
  1. pages/linkedin_extractor.py +92 -43
pages/linkedin_extractor.py CHANGED
@@ -353,11 +353,20 @@ def main():
353
  st.session_state.processing = False
354
 
355
  # Chat management
356
- if st.session_state.chatbot and st.session_state.extracted_data:
357
  st.markdown("---")
358
  st.subheader("πŸ’¬ Chat Management")
359
  if st.button("πŸ—‘οΈ Clear Chat History", type="secondary", use_container_width=True):
360
  clear_chat_history()
 
 
 
 
 
 
 
 
 
361
 
362
  # Main content area
363
  col1, col2 = st.columns([1, 1])
@@ -422,53 +431,93 @@ def main():
422
  with col2:
423
  st.markdown("### πŸ’¬ AI Chat Analysis")
424
 
425
- if st.session_state.chatbot and st.session_state.extracted_data:
426
- # Display chat history
427
- for i, chat in enumerate(st.session_state.chat_history):
428
- if chat["role"] == "user":
429
- st.markdown(f"**πŸ‘€ You:** {chat['content']}")
430
- elif chat["role"] == "assistant":
431
- st.markdown(f"**πŸ€– AI:** {chat['content']}")
432
-
433
- # Chat input
434
- user_input = st.chat_input("Ask about the LinkedIn data...")
 
 
 
435
 
436
- if user_input:
437
- # Add user message
438
- st.session_state.chat_history.append({"role": "user", "content": user_input})
439
 
440
- # Generate AI response
441
- with st.spinner("πŸ€” Mistral AI is analyzing..."):
442
- try:
443
- response = st.session_state.chatbot.invoke({"question": user_input})
444
- answer = response.get("answer", "I couldn't generate a response based on the available data.")
445
-
446
- st.session_state.chat_history.append({"role": "assistant", "content": answer})
447
- st.rerun()
448
- except Exception as e:
449
- error_msg = f"❌ Error generating response: {str(e)}"
450
- st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
451
- st.rerun()
452
-
453
- # Suggested questions
454
- if not st.session_state.chat_history:
455
- st.markdown("#### πŸ’‘ Suggested Questions")
456
- suggestions = [
457
- "Summarize the main information from this page",
458
- "What are the key highlights or achievements?",
459
- "Analyze the business or professional focus",
460
- "What insights can you extract from this content?",
461
- "Provide a comprehensive overview"
462
- ]
 
 
 
 
 
463
 
464
- for suggestion in suggestions:
465
- if st.button(suggestion, key=f"suggest_{suggestion}", use_container_width=True):
466
- st.info(f"πŸ’‘ Try asking: '{suggestion}'")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
 
468
- elif st.session_state.extracted_data:
469
- st.info("πŸ’¬ Start a conversation with the AI assistant")
470
  else:
471
- st.info("πŸ” Extract LinkedIn data to enable AI analysis")
 
 
 
 
 
 
 
 
 
472
 
473
  # Features section
474
  st.markdown("---")
 
353
  st.session_state.processing = False
354
 
355
  # Chat management
356
+ if st.session_state.extracted_data and st.session_state.extracted_data.get("status") == "success":
357
  st.markdown("---")
358
  st.subheader("πŸ’¬ Chat Management")
359
  if st.button("πŸ—‘οΈ Clear Chat History", type="secondary", use_container_width=True):
360
  clear_chat_history()
361
+
362
+ # Debug info (optional)
363
+ if st.checkbox("πŸ”§ Show Debug Info", False):
364
+ st.markdown("### Debug Information")
365
+ st.write("Extracted Data:", st.session_state.extracted_data is not None)
366
+ st.write("Vectorstore:", st.session_state.vectorstore is not None)
367
+ st.write("Chatbot:", st.session_state.chatbot is not None)
368
+ st.write("Chat History Length:", len(st.session_state.chat_history))
369
+ st.write("Processing:", st.session_state.processing)
370
 
371
  # Main content area
372
  col1, col2 = st.columns([1, 1])
 
431
  with col2:
432
  st.markdown("### πŸ’¬ AI Chat Analysis")
433
 
434
+ # Check if we have everything needed for chat
435
+ has_extracted_data = st.session_state.extracted_data and st.session_state.extracted_data.get("status") == "success"
436
+ has_vectorstore = st.session_state.vectorstore is not None
437
+
438
+ if has_extracted_data and has_vectorstore:
439
+ # Initialize chatbot if not exists
440
+ if st.session_state.chatbot is None:
441
+ with st.spinner("πŸ”„ Initializing AI Chat..."):
442
+ st.session_state.chatbot = create_chatbot(st.session_state.vectorstore)
443
+ if st.session_state.chatbot:
444
+ st.success("βœ… AI Chat ready!")
445
+ else:
446
+ st.error("❌ Failed to initialize AI chat")
447
 
448
+ # Display chat interface when chatbot is ready
449
+ if st.session_state.chatbot:
450
+ st.success("πŸ’¬ Chat with Mistral AI about the LinkedIn data!")
451
 
452
+ # Display chat history
453
+ for chat in st.session_state.chat_history:
454
+ if chat["role"] == "user":
455
+ with st.chat_message("user"):
456
+ st.write(chat['content'])
457
+ elif chat["role"] == "assistant":
458
+ with st.chat_message("assistant"):
459
+ st.write(chat['content'])
460
+
461
+ # Chat input - ALWAYS VISIBLE when ready
462
+ user_input = st.chat_input("Ask about the LinkedIn data...")
463
+
464
+ if user_input:
465
+ # Add user message to history and display
466
+ st.session_state.chat_history.append({"role": "user", "content": user_input})
467
+
468
+ # Generate AI response
469
+ with st.spinner("πŸ€” Mistral AI is analyzing..."):
470
+ try:
471
+ response = st.session_state.chatbot.invoke({"question": user_input})
472
+ answer = response.get("answer", "I couldn't generate a response based on the available data.")
473
+
474
+ st.session_state.chat_history.append({"role": "assistant", "content": answer})
475
+ st.rerun()
476
+ except Exception as e:
477
+ error_msg = f"❌ Error generating response: {str(e)}"
478
+ st.session_state.chat_history.append({"role": "assistant", "content": error_msg})
479
+ st.rerun()
480
 
481
+ # Suggested questions - only show when no chat history
482
+ if len(st.session_state.chat_history) == 0:
483
+ st.markdown("#### πŸ’‘ Try asking:")
484
+ suggestions = [
485
+ "Summarize the main information from this LinkedIn page",
486
+ "What are the key highlights or achievements mentioned?",
487
+ "Analyze the professional focus and expertise",
488
+ "What insights can you extract from this content?",
489
+ "Provide a comprehensive overview of this profile"
490
+ ]
491
+
492
+ for suggestion in suggestions:
493
+ if st.button(suggestion, key=f"suggest_{suggestion}", use_container_width=True):
494
+ st.info(f"πŸ’‘ Type this in the chat: '{suggestion}'")
495
+
496
+ elif has_extracted_data and not has_vectorstore:
497
+ st.warning("πŸ”„ Processing data for AI analysis...")
498
+ # Try to process the data
499
+ with st.spinner("Preparing data for AI chat..."):
500
+ vectorstore, chunks = process_extracted_data(st.session_state.extracted_data)
501
+ if vectorstore:
502
+ st.session_state.vectorstore = vectorstore
503
+ st.rerun()
504
+ else:
505
+ st.error("❌ Failed to process data for AI analysis")
506
+
507
+ elif st.session_state.processing:
508
+ st.info("πŸ”„ Extracting and processing LinkedIn data...")
509
 
 
 
510
  else:
511
+ st.info("""
512
+ πŸ” **Extract LinkedIn data to enable AI analysis**
513
+
514
+ Once data is extracted, you can:
515
+ - Ask questions about the content
516
+ - Get summaries and insights
517
+ - Analyze professional information
518
+ - Extract key achievements
519
+ - Discuss career highlights
520
+ """)
521
 
522
  # Features section
523
  st.markdown("---")