Update pages/linkedin_extractor.py
Browse files- 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 |
-
|
| 464 |
-
|
| 465 |
|
| 466 |
-
|
| 467 |
-
st.
|
|
|
|
|
|
|
| 468 |
|
| 469 |
-
|
| 470 |
-
st.info("π Processing LinkedIn data...")
|
| 471 |
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 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 |
-
|
| 522 |
-
st.
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 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 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("---")
|