Spaces:
Runtime error
Runtime error
updates
Browse files
app.py
CHANGED
|
@@ -1,396 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
text-decoration: none;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
a:visited {
|
| 188 |
-
color: #551A8B;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
.container {
|
| 192 |
-
width: 85%;
|
| 193 |
-
margin: auto;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
table {
|
| 197 |
-
width: 100%;
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
.header-table {
|
| 201 |
-
width: 100%;
|
| 202 |
-
background-color: #ff6600;
|
| 203 |
-
padding: 2px 10px;
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
.header-table a {
|
| 207 |
-
color: black;
|
| 208 |
-
font-weight: bold;
|
| 209 |
-
font-size: 14pt;
|
| 210 |
-
text-decoration: none;
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
.itemlist .athing {
|
| 214 |
-
background-color: #f6f6ef;
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
.rank {
|
| 218 |
-
font-size: 14pt;
|
| 219 |
-
color: #828282;
|
| 220 |
-
padding-right: 5px;
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
.storylink {
|
| 224 |
-
font-size: 10pt;
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
.subtext {
|
| 228 |
-
font-size: 8pt;
|
| 229 |
-
color: #828282;
|
| 230 |
-
padding-left: 40px;
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
.subtext a {
|
| 234 |
-
color: #828282;
|
| 235 |
-
text-decoration: none;
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
#refresh-button {
|
| 239 |
-
background: none;
|
| 240 |
-
border: none;
|
| 241 |
-
color: black;
|
| 242 |
-
font-weight: bold;
|
| 243 |
-
font-size: 14pt;
|
| 244 |
-
cursor: pointer;
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
.no-papers {
|
| 248 |
-
text-align: center;
|
| 249 |
-
color: #828282;
|
| 250 |
-
padding: 1rem;
|
| 251 |
-
font-size: 14pt;
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
@media (max-width: 640px) {
|
| 255 |
-
.header-table a {
|
| 256 |
-
font-size: 12pt;
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
.storylink {
|
| 260 |
-
font-size: 9pt;
|
| 261 |
-
}
|
| 262 |
-
|
| 263 |
-
.subtext {
|
| 264 |
-
font-size: 7pt;
|
| 265 |
-
}
|
| 266 |
-
}
|
| 267 |
-
|
| 268 |
-
/* Dark mode */
|
| 269 |
-
@media (prefers-color-scheme: dark) {
|
| 270 |
-
body {
|
| 271 |
-
background-color: #121212;
|
| 272 |
-
color: #e0e0e0;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
a {
|
| 276 |
-
color: #add8e6;
|
| 277 |
-
}
|
| 278 |
-
|
| 279 |
-
a:visited {
|
| 280 |
-
color: #9370db;
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
-
.header-table {
|
| 284 |
-
background-color: #ff6600;
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
.header-table a {
|
| 288 |
-
color: black;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
.itemlist .athing {
|
| 292 |
-
background-color: #1e1e1e;
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
.rank {
|
| 296 |
-
color: #b0b0b0;
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
.subtext {
|
| 300 |
-
color: #b0b0b0;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.subtext a {
|
| 304 |
-
color: #b0b0b0;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
#refresh-button {
|
| 308 |
-
color: #e0e0e0;
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
.no-papers {
|
| 312 |
-
color: #b0b0b0;
|
| 313 |
-
}
|
| 314 |
-
}
|
| 315 |
"""
|
| 316 |
|
| 317 |
-
demo = gr.Blocks(css=css)
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
|
| 326 |
-
**Step 1:** Search for your paper and index on Hugging Face:
|
| 327 |
-
[https://huggingface.co/papers?search=true](https://huggingface.co/papers?search=true)
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
| 336 |
with gr.Row():
|
| 337 |
-
gr.
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
# Time Filter Dropdown
|
| 353 |
-
with gr.Row(elem_classes=["time-filter-row"], elem_id="time-filter-row"):
|
| 354 |
-
gr.HTML("<label for='time-filter'>Filter by Timeframe: </label>")
|
| 355 |
-
time_filter_dropdown = gr.Dropdown(
|
| 356 |
-
choices=["All Time", "Last Week", "Last Month", "Last Year"],
|
| 357 |
-
value="All Time",
|
| 358 |
-
label="Timeframe",
|
| 359 |
-
interactive=True,
|
| 360 |
-
elem_id="time-filter-dropdown"
|
| 361 |
-
)
|
| 362 |
-
|
| 363 |
-
# Paper list
|
| 364 |
-
paper_list = gr.HTML()
|
| 365 |
-
|
| 366 |
-
# Navigation Buttons
|
| 367 |
with gr.Row():
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
time_filter_dropdown.change(
|
| 382 |
-
paper_manager.set_time_filter,
|
| 383 |
-
inputs=[time_filter_dropdown],
|
| 384 |
-
outputs=[paper_list]
|
| 385 |
)
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
-
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
import datetime
|
| 4 |
+
import operator
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import tqdm.auto
|
| 7 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
| 8 |
+
from huggingface_hub import HfApi
|
| 9 |
+
from ragatouille import RAGPretrainedModel
|
| 10 |
+
|
| 11 |
import gradio as gr
|
| 12 |
+
from gradio_calendar import Calendar
|
| 13 |
+
import datasets
|
| 14 |
+
|
| 15 |
+
# --- Data Loading and Processing ---
|
| 16 |
+
|
| 17 |
+
api = HfApi()
|
| 18 |
+
|
| 19 |
+
INDEX_REPO_ID = "hysts-bot-data/daily-papers-abstract-index"
|
| 20 |
+
INDEX_DIR_PATH = ".ragatouille/colbert/indexes/daily-papers-abstract-index/"
|
| 21 |
+
api.snapshot_download(
|
| 22 |
+
repo_id=INDEX_REPO_ID,
|
| 23 |
+
repo_type="dataset",
|
| 24 |
+
local_dir=INDEX_DIR_PATH,
|
| 25 |
+
)
|
| 26 |
+
abstract_retriever = RAGPretrainedModel.from_index(INDEX_DIR_PATH)
|
| 27 |
+
# Run once to initialize the retriever
|
| 28 |
+
abstract_retriever.search("LLM")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def update_abstract_index() -> None:
|
| 32 |
+
global abstract_retriever
|
| 33 |
+
|
| 34 |
+
api.snapshot_download(
|
| 35 |
+
repo_id=INDEX_REPO_ID,
|
| 36 |
+
repo_type="dataset",
|
| 37 |
+
local_dir=INDEX_DIR_PATH,
|
| 38 |
+
)
|
| 39 |
+
abstract_retriever = RAGPretrainedModel.from_index(INDEX_DIR_PATH)
|
| 40 |
+
abstract_retriever.search("LLM")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
scheduler_abstract = BackgroundScheduler()
|
| 44 |
+
scheduler_abstract.add_job(
|
| 45 |
+
func=update_abstract_index,
|
| 46 |
+
trigger="cron",
|
| 47 |
+
minute=0, # Every hour at minute 0
|
| 48 |
+
timezone="UTC",
|
| 49 |
+
misfire_grace_time=3 * 60,
|
| 50 |
+
)
|
| 51 |
+
scheduler_abstract.start()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def get_df() -> pd.DataFrame:
|
| 55 |
+
df = pd.merge(
|
| 56 |
+
left=datasets.load_dataset("hysts-bot-data/daily-papers", split="train").to_pandas(),
|
| 57 |
+
right=datasets.load_dataset("hysts-bot-data/daily-papers-stats", split="train").to_pandas(),
|
| 58 |
+
on="arxiv_id",
|
| 59 |
+
)
|
| 60 |
+
df = df[::-1].reset_index(drop=True)
|
| 61 |
+
df["date"] = df["date"].dt.strftime("%Y-%m-%d")
|
| 62 |
+
|
| 63 |
+
paper_info = []
|
| 64 |
+
for _, row in tqdm.auto.tqdm(df.iterrows(), total=len(df)):
|
| 65 |
+
info = row.copy()
|
| 66 |
+
del info["abstract"]
|
| 67 |
+
info["paper_page"] = f"https://huggingface.co/papers/{row.arxiv_id}"
|
| 68 |
+
paper_info.append(info)
|
| 69 |
+
return pd.DataFrame(paper_info)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class Prettifier:
|
| 73 |
+
@staticmethod
|
| 74 |
+
def get_github_link(link: str) -> str:
|
| 75 |
+
if not link:
|
| 76 |
+
return ""
|
| 77 |
+
return Prettifier.create_link("github", link)
|
| 78 |
+
|
| 79 |
+
@staticmethod
|
| 80 |
+
def create_link(text: str, url: str) -> str:
|
| 81 |
+
return f'<a href="{url}" target="_blank">{text}</a>'
|
| 82 |
+
|
| 83 |
+
@staticmethod
|
| 84 |
+
def to_div(text: str | None, category_name: str) -> str:
|
| 85 |
+
if text is None:
|
| 86 |
+
text = ""
|
| 87 |
+
class_name = f"{category_name}-{text.lower()}"
|
| 88 |
+
return f'<div class="{class_name}">{text}</div>'
|
| 89 |
+
|
| 90 |
+
def __call__(self, df: pd.DataFrame) -> pd.DataFrame:
|
| 91 |
+
new_rows = []
|
| 92 |
+
for _, row in df.iterrows():
|
| 93 |
+
new_row = {
|
| 94 |
+
"date": Prettifier.create_link(row.date, f"https://huggingface.co/papers?date={row.date}"),
|
| 95 |
+
"paper_page": Prettifier.create_link(row.arxiv_id, row.paper_page),
|
| 96 |
+
"title": row["title"],
|
| 97 |
+
"github": self.get_github_link(row.github),
|
| 98 |
+
"👍": row["upvotes"],
|
| 99 |
+
"💬": row["num_comments"],
|
| 100 |
+
}
|
| 101 |
+
new_rows.append(new_row)
|
| 102 |
+
return pd.DataFrame(new_rows)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class PaperList:
|
| 106 |
+
COLUMN_INFO = [
|
| 107 |
+
["date", "markdown"],
|
| 108 |
+
["paper_page", "markdown"],
|
| 109 |
+
["title", "str"],
|
| 110 |
+
["github", "markdown"],
|
| 111 |
+
["👍", "number"],
|
| 112 |
+
["💬", "number"],
|
| 113 |
+
]
|
| 114 |
+
|
| 115 |
+
def __init__(self, df: pd.DataFrame):
|
| 116 |
+
self.df_raw = df
|
| 117 |
+
self._prettifier = Prettifier()
|
| 118 |
+
self.df_prettified = self._prettifier(df).loc[:, self.column_names]
|
| 119 |
+
|
| 120 |
+
@property
|
| 121 |
+
def column_names(self):
|
| 122 |
+
return list(map(operator.itemgetter(0), self.COLUMN_INFO))
|
| 123 |
+
|
| 124 |
+
@property
|
| 125 |
+
def column_datatype(self):
|
| 126 |
+
return list(map(operator.itemgetter(1), self.COLUMN_INFO))
|
| 127 |
+
|
| 128 |
+
def search(
|
| 129 |
+
self,
|
| 130 |
+
start_date: datetime.datetime,
|
| 131 |
+
end_date: datetime.datetime,
|
| 132 |
+
title_search_query: str,
|
| 133 |
+
abstract_search_query: str,
|
| 134 |
+
max_num_to_retrieve: int,
|
| 135 |
+
) -> pd.DataFrame:
|
| 136 |
+
df = self.df_raw.copy()
|
| 137 |
+
df["date"] = pd.to_datetime(df["date"])
|
| 138 |
+
|
| 139 |
+
# Filter by date
|
| 140 |
+
df = df[(df["date"] >= start_date) & (df["date"] <= end_date)]
|
| 141 |
+
df["date"] = df["date"].dt.strftime("%Y-%m-%d")
|
| 142 |
+
|
| 143 |
+
# Filter by title
|
| 144 |
+
if title_search_query:
|
| 145 |
+
df = df[df["title"].str.contains(title_search_query, case=False)]
|
| 146 |
+
|
| 147 |
+
# Filter by abstract
|
| 148 |
+
if abstract_search_query:
|
| 149 |
+
results = abstract_retriever.search(abstract_search_query, k=max_num_to_retrieve)
|
| 150 |
+
remaining_ids = set(df["arxiv_id"])
|
| 151 |
+
found_id_set = set()
|
| 152 |
+
found_ids = []
|
| 153 |
+
for x in results:
|
| 154 |
+
arxiv_id = x["document_id"]
|
| 155 |
+
if arxiv_id not in remaining_ids:
|
| 156 |
+
continue
|
| 157 |
+
if arxiv_id in found_id_set:
|
| 158 |
+
continue
|
| 159 |
+
found_id_set.add(arxiv_id)
|
| 160 |
+
found_ids.append(arxiv_id)
|
| 161 |
+
df = df[df["arxiv_id"].isin(found_ids)].set_index("arxiv_id").reindex(index=found_ids).reset_index()
|
| 162 |
+
|
| 163 |
+
df_prettified = self._prettifier(df).loc[:, self.column_names]
|
| 164 |
+
return df_prettified
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
paper_list = PaperList(get_df())
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def update_paper_list() -> None:
|
| 171 |
+
global paper_list
|
| 172 |
+
paper_list = PaperList(get_df())
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
scheduler_data = BackgroundScheduler()
|
| 176 |
+
scheduler_data.add_job(
|
| 177 |
+
func=update_paper_list,
|
| 178 |
+
trigger="cron",
|
| 179 |
+
minute=0, # Every hour at minute 0
|
| 180 |
+
timezone="UTC",
|
| 181 |
+
misfire_grace_time=60,
|
| 182 |
+
)
|
| 183 |
+
scheduler_data.start()
|
| 184 |
+
|
| 185 |
+
# --- Gradio App ---
|
| 186 |
+
|
| 187 |
+
DESCRIPTION = "# [Daily Papers](https://huggingface.co/papers)"
|
| 188 |
+
|
| 189 |
+
FOOT_NOTE = """\
|
| 190 |
+
Related useful Spaces:
|
| 191 |
+
- [Semantic Scholar Paper Recommender](https://huggingface.co/spaces/librarian-bots/recommend_similar_papers) by [davanstrien](https://huggingface.co/davanstrien)
|
| 192 |
+
- [ArXiv CS RAG](https://huggingface.co/spaces/bishmoy/Arxiv-CS-RAG) by [bishmoy](https://huggingface.co/bishmoy)
|
| 193 |
+
- [Paper Q&A](https://huggingface.co/spaces/chansung/paper_qa) by [chansung](https://huggingface.co/chansung)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
"""
|
| 195 |
|
|
|
|
| 196 |
|
| 197 |
+
def update_df() -> pd.DataFrame:
|
| 198 |
+
return paper_list.df_prettified
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def update_num_papers(df: pd.DataFrame) -> str:
|
| 202 |
+
return f"{len(df)} / {len(paper_list.df_raw)}"
|
| 203 |
|
|
|
|
|
|
|
| 204 |
|
| 205 |
+
def search(
|
| 206 |
+
start_date: datetime.datetime,
|
| 207 |
+
end_date: datetime.datetime,
|
| 208 |
+
search_title: str,
|
| 209 |
+
search_abstract: str,
|
| 210 |
+
max_num_to_retrieve: int,
|
| 211 |
+
) -> pd.DataFrame:
|
| 212 |
+
return paper_list.search(start_date, end_date, search_title, search_abstract, max_num_to_retrieve)
|
| 213 |
|
| 214 |
+
|
| 215 |
+
with gr.Blocks(css="style.css") as demo:
|
| 216 |
+
gr.Markdown(DESCRIPTION)
|
| 217 |
+
with gr.Group():
|
| 218 |
+
search_title = gr.Textbox(label="Search title")
|
| 219 |
with gr.Row():
|
| 220 |
+
with gr.Column(scale=4):
|
| 221 |
+
search_abstract = gr.Textbox(
|
| 222 |
+
label="Search abstract",
|
| 223 |
+
info="The result may not be accurate as the abstract does not contain all the information.",
|
| 224 |
+
)
|
| 225 |
+
with gr.Column(scale=1):
|
| 226 |
+
max_num_to_retrieve = gr.Slider(
|
| 227 |
+
label="Max number to retrieve",
|
| 228 |
+
info="This is used only for search on abstracts.",
|
| 229 |
+
minimum=1,
|
| 230 |
+
maximum=len(paper_list.df_raw),
|
| 231 |
+
step=1,
|
| 232 |
+
value=100,
|
| 233 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
with gr.Row():
|
| 235 |
+
start_date = Calendar(label="Start date", type="date", value="2023-05-05")
|
| 236 |
+
end_date = Calendar(label="End date", type="date", value=datetime.datetime.utcnow().strftime("%Y-%m-%d"))
|
| 237 |
+
|
| 238 |
+
num_papers = gr.Textbox(label="Number of papers", value=update_num_papers(paper_list.df_raw), interactive=False)
|
| 239 |
+
df = gr.Dataframe(
|
| 240 |
+
value=paper_list.df_prettified,
|
| 241 |
+
datatype=paper_list.column_datatype,
|
| 242 |
+
type="pandas",
|
| 243 |
+
interactive=False,
|
| 244 |
+
height=1000,
|
| 245 |
+
elem_id="table",
|
| 246 |
+
column_widths=["10%", "10%", "60%", "10%", "5%", "5%"],
|
| 247 |
+
wrap=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
)
|
| 249 |
|
| 250 |
+
gr.Markdown(FOOT_NOTE)
|
| 251 |
+
|
| 252 |
+
# Define the triggers and corresponding functions
|
| 253 |
+
search_event = gr.Button("Search")
|
| 254 |
+
search_event.click(
|
| 255 |
+
fn=search,
|
| 256 |
+
inputs=[start_date, end_date, search_title, search_abstract, max_num_to_retrieve],
|
| 257 |
+
outputs=df,
|
| 258 |
+
).then(
|
| 259 |
+
fn=update_num_papers,
|
| 260 |
+
inputs=df,
|
| 261 |
+
outputs=num_papers,
|
| 262 |
+
queue=False,
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
# Automatically trigger search when inputs change
|
| 266 |
+
for trigger in [start_date, end_date, search_title, search_abstract, max_num_to_retrieve]:
|
| 267 |
+
trigger.change(
|
| 268 |
+
fn=search,
|
| 269 |
+
inputs=[start_date, end_date, search_title, search_abstract, max_num_to_retrieve],
|
| 270 |
+
outputs=df,
|
| 271 |
+
).then(
|
| 272 |
+
fn=update_num_papers,
|
| 273 |
+
inputs=df,
|
| 274 |
+
outputs=num_papers,
|
| 275 |
+
queue=False,
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
# Load the initial dataframe and number of papers
|
| 279 |
+
demo.load(
|
| 280 |
+
fn=update_df,
|
| 281 |
+
outputs=df,
|
| 282 |
+
queue=False,
|
| 283 |
+
).then(
|
| 284 |
+
fn=update_num_papers,
|
| 285 |
+
inputs=df,
|
| 286 |
+
outputs=num_papers,
|
| 287 |
+
queue=False,
|
| 288 |
+
)
|
| 289 |
|
| 290 |
+
if __name__ == "__main__":
|
| 291 |
+
demo.queue(api_open=False).launch(show_api=False)
|