Update pages/linkedin_extractor.py
Browse files- 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.
|
| 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
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
st.
|
| 439 |
|
| 440 |
-
#
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
st.
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
"
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
|
| 468 |
-
elif st.session_state.extracted_data:
|
| 469 |
-
st.info("π¬ Start a conversation with the AI assistant")
|
| 470 |
else:
|
| 471 |
-
st.info("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("---")
|