akhaliq HF staff commited on
Commit
4523ad3
·
verified ·
1 Parent(s): a575839

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -28,7 +28,7 @@ def get_df() -> pd.DataFrame:
28
  df_stats = datasets.load_dataset("hysts-bot-data/daily-papers-stats", split="train").to_pandas()
29
 
30
  # Merge datasets on 'arxiv_id'
31
- df = pd.merge(left=df_papers, right=df_stats, on="arxiv_id")
32
 
33
  # Reverse the DataFrame to have the latest papers first
34
  df = df[::-1].reset_index(drop=True)
@@ -164,7 +164,7 @@ class PaperManager:
164
  Calculate the score of a paper based on upvotes and age.
165
  This mimics the "hotness" algorithm used by platforms like Hacker News.
166
  """
167
- upvotes = row.get('👍', 0)
168
  date_str = row.get('date', datetime.datetime.now(timezone.utc).strftime("%Y-%m-%d"))
169
  try:
170
  published_time = datetime.datetime.strptime(date_str, "%Y-%m-%d").replace(tzinfo=timezone.utc)
@@ -190,8 +190,12 @@ class PaperManager:
190
  df = df[df["title"].str.contains(self.current_search_query, case=False, na=False)]
191
 
192
  if self.sort_method == "hot":
193
- df['score'] = df.apply(self.calculate_score, axis=1)
194
- df_sorted = df.sort_values(by='score', ascending=False).drop(columns=['score'])
 
 
 
 
195
  elif self.sort_method == "new":
196
  df_sorted = df.sort_values(by='date', ascending=False) # Sort by 'date'
197
  elif self.sort_method == "top":
@@ -677,13 +681,6 @@ with demo:
677
  outputs=[paper_list]
678
  )
679
 
680
- # Footer
681
- gr.Markdown("""
682
- Related useful Spaces:
683
- - [Semantic Scholar Paper Recommender](https://huggingface.co/spaces/librarian-bots/recommend_similar_papers) by [davanstrien](https://huggingface.co/davanstrien)
684
- - [ArXiv CS RAG](https://huggingface.co/spaces/bishmoy/Arxiv-CS-RAG) by [bishmoy](https://huggingface.co/bishmoy)
685
- - [Paper Q&A](https://huggingface.co/spaces/chansung/paper_qa) by [chansung](https://huggingface.co/chansung)
686
- """)
687
 
688
 
689
  # --- Launch the App ---
 
28
  df_stats = datasets.load_dataset("hysts-bot-data/daily-papers-stats", split="train").to_pandas()
29
 
30
  # Merge datasets on 'arxiv_id'
31
+ df = pd.merge(left=df_papers, right=df_stats, on="arxiv_id", suffixes=('_papers', '_stats'))
32
 
33
  # Reverse the DataFrame to have the latest papers first
34
  df = df[::-1].reset_index(drop=True)
 
164
  Calculate the score of a paper based on upvotes and age.
165
  This mimics the "hotness" algorithm used by platforms like Hacker News.
166
  """
167
+ upvotes = row.get('upvotes', 0) # Corrected from '👍' to 'upvotes'
168
  date_str = row.get('date', datetime.datetime.now(timezone.utc).strftime("%Y-%m-%d"))
169
  try:
170
  published_time = datetime.datetime.strptime(date_str, "%Y-%m-%d").replace(tzinfo=timezone.utc)
 
190
  df = df[df["title"].str.contains(self.current_search_query, case=False, na=False)]
191
 
192
  if self.sort_method == "hot":
193
+ if not df.empty:
194
+ df = df.drop(columns=['score'], errors='ignore') # Remove existing 'score' column if present
195
+ df['score'] = df.apply(self.calculate_score, axis=1)
196
+ df_sorted = df.sort_values(by='score', ascending=False).drop(columns=['score'])
197
+ else:
198
+ df_sorted = df
199
  elif self.sort_method == "new":
200
  df_sorted = df.sort_values(by='date', ascending=False) # Sort by 'date'
201
  elif self.sort_method == "top":
 
681
  outputs=[paper_list]
682
  )
683
 
 
 
 
 
 
 
 
684
 
685
 
686
  # --- Launch the App ---