File size: 5,219 Bytes
edb3b94 cf34627 edb3b94 cf34627 edb3b94 cf34627 88b33ec cf34627 edb3b94 cf34627 edb3b94 d88dcaa 88b33ec cf34627 88b33ec cf34627 edb3b94 d88dcaa edb3b94 d88dcaa edb3b94 cf34627 edb3b94 cf34627 edb3b94 | 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 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 185 186 187 188 | #!/usr/bin/env python
import datetime
import gradio as gr
import pandas as pd
from apscheduler.schedulers.background import BackgroundScheduler
from gradio_calendar import Calendar
from papers import PaperList, get_df
DESCRIPTION = "# Papers Leaderboard\nExplore the latest papers and filter by date, title, or abstract keywords."
FOOT_NOTE = "Community: https://discord.gg/openfreeai"
paper_list = PaperList(get_df())
def update_paper_list() -> None:
global paper_list
paper_list = PaperList(get_df())
scheduler = BackgroundScheduler()
scheduler.add_job(func=update_paper_list, trigger="cron", hour="*", timezone="UTC", misfire_grace_time=60)
scheduler.start()
def update_df() -> gr.Dataframe:
return gr.Dataframe(value=paper_list.df_prettified)
def update_num_papers(df: pd.DataFrame) -> str:
return f"{len(df)} / {len(paper_list.df_raw)}"
def search(
start_date: datetime.datetime,
end_date: datetime.datetime,
search_title: str,
search_abstract: str,
max_num_to_retrieve: int,
) -> pd.DataFrame:
return paper_list.search(start_date, end_date, search_title, search_abstract, max_num_to_retrieve)
# ------------------------------------------------------------------
# CSS
# ------------------------------------------------------------------
css = """
body {
margin: 0;
padding: 0;
background: linear-gradient(135deg, #eef2ff 0%, #fdfdfd 100%);
font-family: "Helvetica Neue", Arial, sans-serif;
}
#hero-section {
background: linear-gradient(135deg, #3b82f6 0%, #9333ea 100%);
padding: 2rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
color: white;
}
#hero-section h1 {
font-size: 2.2rem;
margin-bottom: 0.5rem;
}
.search-container {
background-color: #ffffffdd;
backdrop-filter: blur(6px);
border-radius: 0.75rem;
padding: 1rem 1.5rem;
box-shadow: 0 3px 5px rgba(0,0,0,0.1);
margin-bottom: 1rem;
}
.card {
background-color: #fff;
border-radius: 0.75rem;
padding: 1.5rem;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
}
#table table {
border-collapse: collapse;
width: 100%;
background: #fafafa;
}
#table th, #table td {
border: 1px solid #e5e7eb;
padding: 0.5rem;
text-align: left;
}
#table thead {
background-color: #f3f4f6;
font-weight: 600;
}
.footer {
color: #6b7280;
font-size: 0.9rem;
text-align: center;
margin-top: 2rem;
}
"""
with gr.Blocks(css=css) as demo:
# Hero 섹션
gr.HTML(
"""
<div id="hero-section">
<h1>Papers Leaderboard</h1>
<p>Explore the latest papers and filter by date, title, or abstract keywords.</p>
</div>
"""
)
# Search & Filter 헤더 및 외부 링크
gr.Markdown(
"[Exp] AI‑Powered Research Impact Predictor ↗](https://huggingface.co/spaces/VIDraft/PapersImpact)",
elem_classes="search-container"
)
# 검색 입력
with gr.Group():
search_title = gr.Textbox(label="Search title")
with gr.Row():
with gr.Column(scale=4):
search_abstract = gr.Textbox(
label="Search abstract",
info="Search within abstracts (may not be fully accurate).",
)
with gr.Column(scale=1):
max_num_to_retrieve = gr.Slider(
label="Max number to retrieve",
info="Applies only to abstract-based searching",
minimum=1,
maximum=len(paper_list.df_raw),
step=1,
value=100,
)
with gr.Row():
start_date = Calendar(label="Start date", type="datetime", value="2023-05-05")
end_date = Calendar(label="End date", type="datetime")
# 결과: 통계 및 테이블
with gr.Group(elem_id="results-section"):
with gr.Group(elem_classes="card"):
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,
max_height=800,
elem_id="table",
column_widths=["10%", "10%", "60%", "10%", "5%", "5%"],
wrap=True,
)
gr.Markdown(FOOT_NOTE, elem_classes="footer")
# 이벤트 연결
gr.on(
triggers=[start_date.change, end_date.change, search_title.submit, search_abstract.submit],
fn=search,
inputs=[start_date, end_date, search_title, search_abstract, max_num_to_retrieve],
outputs=df,
api_name=False,
).then(
fn=update_num_papers,
inputs=df,
outputs=num_papers,
queue=False,
api_name=False,
)
demo.load(
fn=update_df,
outputs=df,
queue=False,
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)
|