File size: 1,848 Bytes
08080f2
 
b4eb3ca
 
08080f2
9f6546e
4a02364
08080f2
 
b4eb3ca
 
9fb4b90
08080f2
9fb4b90
08080f2
9fb4b90
 
 
 
b4eb3ca
2716ba4
9f6546e
 
 
 
 
9fb4b90
2716ba4
4a02364
 
 
 
57102fb
9f6546e
 
9fb4b90
 
 
 
 
2176657
 
c9a6eb5
 
9fb4b90
3ace5d1
4a02364
5972bae
57102fb
 
4a02364
 
9f6546e
 
 
 
 
 
4a02364
 
3ace5d1
57102fb
1
2
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
#!/usr/bin/env python

import os

import gradio as gr
import pandas as pd
from gradio_calendar import Calendar

from papers import PaperList, get_df
from update_scheduler import UpdateScheduler

DESCRIPTION = "# [Daily Papers](https://huggingface.co/papers)"

paper_list = PaperList(get_df("papers.csv"))

if (SPACE_ID := os.getenv("SPACE_ID")) is not None:
    CRON_HOUR = os.getenv("CRON_HOUR", "*/4")
    CRON_MINUTE = os.getenv("CRON_MINUTE", "0")
    scheduler = UpdateScheduler(space_id=SPACE_ID, cron_hour=CRON_HOUR, cron_minute=CRON_MINUTE)
    scheduler.start()


def update_num_papers(df: pd.DataFrame) -> str:
    return f"{len(df)} / {len(paper_list.df_raw)}"


with gr.Blocks(css="style.css") as demo:
    gr.Markdown(DESCRIPTION)
    with gr.Group():
        with gr.Row():
            start_date = Calendar(label="Start date", type="datetime", value="2023-05-05")
            end_date = Calendar(label="End date", type="datetime")
        search_title = gr.Textbox(label="Search by title")

    num_papers = gr.Textbox(label="Number of papers", value=update_num_papers(paper_list.df_raw), interactive=False)
    df = gr.Dataframe(
        value=paper_list.df_prettified,
        datatype=paper_list.column_datatype,
        type="pandas",
        interactive=False,
        height=1000,
        elem_id="table",
        column_widths=["10%", "10%", "60%", "10%", "10%"],
        wrap=True,
    )

    gr.on(
        triggers=[start_date.change, end_date.change, search_title.submit],
        fn=paper_list.search,
        inputs=[start_date, end_date, search_title],
        outputs=df,
        api_name=False,
    ).then(
        fn=update_num_papers,
        inputs=df,
        outputs=num_papers,
        queue=False,
        api_name=False,
    )

if __name__ == "__main__":
    demo.queue(api_open=False).launch(show_api=False)