NimaKL commited on
Commit
44d194a
·
verified ·
1 Parent(s): 1e884ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -34,11 +34,23 @@ def format_neo4j_datetime(dt) -> str:
34
  logger.warning(f"Error formatting datetime: {e}")
35
  return 'Unknown date'
36
 
37
- def format_interest_list(interests: set, max_items: int = 10) -> str:
38
- """Format a list of interests with a limit and show count if truncated."""
 
 
 
 
 
 
 
 
39
  if not interests:
40
  return 'None'
41
- sorted_interests = sorted(interests)
 
 
 
 
42
  if len(sorted_interests) <= max_items:
43
  return ', '.join(sorted_interests)
44
  return f"{', '.join(sorted_interests[:max_items])} (+{len(sorted_interests) - max_items} more)"
@@ -638,9 +650,9 @@ def format_question(q: Dict) -> str:
638
 
639
  interests_display = []
640
  if keywords:
641
- interests_display.append(f"Keywords: {format_interest_list(set(keywords), max_items=3)}")
642
  if topics:
643
- interests_display.append(f"Topics: {format_interest_list(set(topics), max_items=3)}")
644
  interests_str = " | ".join(interests_display) if interests_display else "No common interests found"
645
 
646
  relevance_score = q.get('relevance_score', 0)
@@ -710,42 +722,42 @@ def recommend_questions(user1: str, user2: str) -> Tuple[str, str, str, List[Dic
710
  common_keywords = user1_interests['keywords'] & user2_interests['keywords']
711
  common_topics = user1_interests['topics'] & user2_interests['topics']
712
 
713
- # Format interests summary
714
  interests_summary = f"""
715
  <div class="interests-summary">
716
  <div class="user-interests">
717
  <h3>{user1}'s Interests</h3>
718
  <div class="interest-section">
719
- <strong>Keywords:</strong> {format_interest_list(user1_interests['keywords'], max_items=8)}
720
  </div>
721
  <div class="interest-section">
722
- <strong>Topics:</strong> {format_interest_list(user1_interests['topics'], max_items=5)}
723
  </div>
724
  </div>
725
 
726
  <div class="user-interests">
727
  <h3>{user2}'s Interests</h3>
728
  <div class="interest-section">
729
- <strong>Keywords:</strong> {format_interest_list(user2_interests['keywords'], max_items=8)}
730
  </div>
731
  <div class="interest-section">
732
- <strong>Topics:</strong> {format_interest_list(user2_interests['topics'], max_items=5)}
733
  </div>
734
  </div>
735
 
736
  <div class="common-interests">
737
  <h3>Common Interests</h3>
738
  <div class="interest-section">
739
- <strong>Keywords:</strong> {format_interest_list(common_keywords, max_items=8)}
740
  </div>
741
  <div class="interest-section">
742
- <strong>Topics:</strong> {format_interest_list(common_topics, max_items=5)}
743
  </div>
744
  </div>
745
  </div>
746
  """
747
-
748
- # Get all recommended questions
749
  questions = recommender.find_common_questions(user1, user2, max_questions=50)
750
 
751
  if questions:
 
34
  logger.warning(f"Error formatting datetime: {e}")
35
  return 'Unknown date'
36
 
37
+ def is_displayable_keyword(keyword: str) -> bool:
38
+ """Check if a keyword should be displayed (not just numbers)."""
39
+ if not keyword:
40
+ return False
41
+ # Remove any spaces and check if the remaining string is numeric
42
+ cleaned = keyword.replace(' ', '')
43
+ return not cleaned.isnumeric()
44
+
45
+ def format_interest_list_for_display(interests: set, max_items: int = 10) -> str:
46
+ """Format a list of interests for display, hiding numeric-only keywords."""
47
  if not interests:
48
  return 'None'
49
+ # Filter numeric keywords only for display
50
+ displayable_interests = {interest for interest in interests if is_displayable_keyword(interest)}
51
+ if not displayable_interests:
52
+ return 'None'
53
+ sorted_interests = sorted(displayable_interests)
54
  if len(sorted_interests) <= max_items:
55
  return ', '.join(sorted_interests)
56
  return f"{', '.join(sorted_interests[:max_items])} (+{len(sorted_interests) - max_items} more)"
 
650
 
651
  interests_display = []
652
  if keywords:
653
+ interests_display.append(f"Keywords: {format_interest_list_for_display(set(keywords), max_items=3)}")
654
  if topics:
655
+ interests_display.append(f"Topics: {format_interest_list_for_display(set(topics), max_items=3)}")
656
  interests_str = " | ".join(interests_display) if interests_display else "No common interests found"
657
 
658
  relevance_score = q.get('relevance_score', 0)
 
722
  common_keywords = user1_interests['keywords'] & user2_interests['keywords']
723
  common_topics = user1_interests['topics'] & user2_interests['topics']
724
 
725
+ # Format interests summary using display formatter
726
  interests_summary = f"""
727
  <div class="interests-summary">
728
  <div class="user-interests">
729
  <h3>{user1}'s Interests</h3>
730
  <div class="interest-section">
731
+ <strong>Keywords:</strong> {format_interest_list_for_display(user1_interests['keywords'], max_items=8)}
732
  </div>
733
  <div class="interest-section">
734
+ <strong>Topics:</strong> {format_interest_list_for_display(user1_interests['topics'], max_items=5)}
735
  </div>
736
  </div>
737
 
738
  <div class="user-interests">
739
  <h3>{user2}'s Interests</h3>
740
  <div class="interest-section">
741
+ <strong>Keywords:</strong> {format_interest_list_for_display(user2_interests['keywords'], max_items=8)}
742
  </div>
743
  <div class="interest-section">
744
+ <strong>Topics:</strong> {format_interest_list_for_display(user2_interests['topics'], max_items=5)}
745
  </div>
746
  </div>
747
 
748
  <div class="common-interests">
749
  <h3>Common Interests</h3>
750
  <div class="interest-section">
751
+ <strong>Keywords:</strong> {format_interest_list_for_display(common_keywords, max_items=8)}
752
  </div>
753
  <div class="interest-section">
754
+ <strong>Topics:</strong> {format_interest_list_for_display(common_topics, max_items=5)}
755
  </div>
756
  </div>
757
  </div>
758
  """
759
+
760
+ # Get all recommended questions - using original interests for matching
761
  questions = recommender.find_common_questions(user1, user2, max_questions=50)
762
 
763
  if questions: