fix: update paper list pull api

This commit is contained in:
Tadashi
2025-01-07 08:16:53 +07:00
parent bab65c1c38
commit a45744ded8
2 changed files with 79 additions and 39 deletions

View File

@@ -522,6 +522,9 @@ class ChatPage(BasePage):
self.state_chat,
]
+ self._indices_input,
).then(
lambda: gr.update(visible=False),
outputs=[self.paper_list.accordion],
).then(
fn=None,
inputs=None,
@@ -639,41 +642,58 @@ class ChatPage(BasePage):
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:

View File

@@ -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