Skip to content

Commit

Permalink
fix: update paper list pull api
Browse files Browse the repository at this point in the history
  • Loading branch information
taprosoft committed Jan 7, 2025
1 parent c3a8f78 commit 69047e1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 39 deletions.
90 changes: 55 additions & 35 deletions libs/ktem/ktem/pages/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ def on_register_events(self):
self.state_chat,
]
+ self._indices_input,
).then(
lambda: gr.update(visible=False),
outputs=[self.paper_list.accordion],
).then(
fn=None,
inputs=None,
Expand Down Expand Up @@ -639,41 +642,58 @@ def on_register_events(self):
show_progress="hidden",
)

self.chat_control.conversation.select(
self.chat_control.select_conv,
inputs=[self.chat_control.conversation, self._app.user_id],
outputs=[
self.chat_control.conversation_id,
self.chat_control.conversation,
self.chat_control.conversation_rn,
self.chat_panel.chatbot,
self.followup_questions,
self.info_panel,
self.state_plot_panel,
self.state_retrieval_history,
self.state_plot_history,
self.chat_control.cb_is_public,
self.state_chat,
]
+ self._indices_input,
show_progress="hidden",
).then(
fn=self._json_to_plot,
inputs=self.state_plot_panel,
outputs=self.plot_panel,
).then(
lambda: self.toggle_delete(""),
outputs=[self.chat_control._new_delete, self.chat_control._delete_confirm],
).then(
fn=lambda: True,
js=clear_bot_message_selection_js,
).then(
fn=lambda: True,
inputs=None,
outputs=[self._preview_links],
js=pdfview_js,
).then(
fn=None, inputs=None, outputs=None, js=chat_input_focus_js
onConvSelect = (
self.chat_control.conversation.select(
self.chat_control.select_conv,
inputs=[self.chat_control.conversation, self._app.user_id],
outputs=[
self.chat_control.conversation_id,
self.chat_control.conversation,
self.chat_control.conversation_rn,
self.chat_panel.chatbot,
self.followup_questions,
self.info_panel,
self.state_plot_panel,
self.state_retrieval_history,
self.state_plot_history,
self.chat_control.cb_is_public,
self.state_chat,
]
+ self._indices_input,
show_progress="hidden",
)
.then(
fn=self._json_to_plot,
inputs=self.state_plot_panel,
outputs=self.plot_panel,
)
.then(
lambda: self.toggle_delete(""),
outputs=[
self.chat_control._new_delete,
self.chat_control._delete_confirm,
],
)
)

if KH_DEMO_MODE:
onConvSelect = onConvSelect.then(
lambda: gr.update(visible=False),
outputs=[self.paper_list.accordion],
)

onConvSelect = (
onConvSelect.then(
fn=lambda: True,
js=clear_bot_message_selection_js,
)
.then(
fn=lambda: True,
inputs=None,
outputs=[self._preview_links],
js=pdfview_js,
)
.then(fn=None, inputs=None, outputs=None, js=chat_input_focus_js)
)

if not KH_DEMO_MODE:
Expand Down
28 changes: 24 additions & 4 deletions libs/ktem/ktem/utils/hf_papers.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
from datetime import datetime, timedelta

import requests

HF_API_URL = "https://huggingface.co/api/daily_papers"
ARXIV_URL = "https://arxiv.org/abs/{paper_id}"


# Function to parse the date string
def parse_date(date_str):
return datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ")


def fetch_papers(top_n=5):
try:
response = requests.get(f"{HF_API_URL}?limit=100")
response.raise_for_status()
items = response.json()
items.sort(key=lambda x: x.get("paper", {}).get("upvotes", 0), reverse=True)
items = [

# Calculate the date 3 days ago from now
three_days_ago = datetime.now() - timedelta(days=3)

# Filter items from the last 3 days
recent_items = [
item
for item in items
if parse_date(item.get("publishedAt")) >= three_days_ago
]

recent_items.sort(
key=lambda x: x.get("paper", {}).get("upvotes", 0), reverse=True
)
output_items = [
{
"title": item.get("paper", {}).get("title"),
"url": ARXIV_URL.format(paper_id=item.get("paper", {}).get("id")),
"upvotes": item.get("paper", {}).get("upvotes"),
}
for item in items[:top_n]
for item in recent_items[:top_n]
]
except Exception as e:
print(e)
return []

return items
return output_items

0 comments on commit 69047e1

Please sign in to comment.