Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,11 +40,24 @@ STYLE = """
|
|
| 40 |
border-right: none !important;
|
| 41 |
box-shadow: none !important;
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
"""
|
| 44 |
|
| 45 |
dataset_repo_id = "chansung/auto-paper-qa2"
|
| 46 |
ds = datasets.load_dataset(dataset_repo_id)
|
| 47 |
|
|
|
|
| 48 |
date2qna = {}
|
| 49 |
longest_qans = 0
|
| 50 |
|
|
@@ -72,6 +85,13 @@ for data in ds["train"]:
|
|
| 72 |
else:
|
| 73 |
date2qna[date] = [data]
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
sorted_dates = sorted(date2qna.keys())
|
| 76 |
last_date = sorted_dates[-1]
|
| 77 |
last_papers = date2qna[last_date]
|
|
@@ -125,18 +145,149 @@ def set_paper(date, paper_title):
|
|
| 125 |
gr.Markdown(f"βͺ **(Technical)** {selected_paper['2_additional_breath_q:answers:expert']}"),
|
| 126 |
)
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
with gr.Blocks(css=STYLE) as demo:
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
)
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
)
|
| 141 |
|
| 142 |
title = gr.Markdown(f"# {selected_paper['title']}")
|
|
@@ -215,7 +366,7 @@ with gr.Blocks(css=STYLE) as demo:
|
|
| 215 |
]
|
| 216 |
)
|
| 217 |
|
| 218 |
-
papers_dd.
|
| 219 |
set_paper,
|
| 220 |
[date_dd, papers_dd],
|
| 221 |
[
|
|
@@ -234,4 +385,11 @@ with gr.Blocks(css=STYLE) as demo:
|
|
| 234 |
]
|
| 235 |
)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
demo.launch(share=True)
|
|
|
|
| 40 |
border-right: none !important;
|
| 41 |
box-shadow: none !important;
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
.no-gap {
|
| 45 |
+
gap: 0px;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.no-radius {
|
| 49 |
+
border-radius: 0px;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
#search_input > label > span {
|
| 53 |
+
display: none;
|
| 54 |
+
}
|
| 55 |
"""
|
| 56 |
|
| 57 |
dataset_repo_id = "chansung/auto-paper-qa2"
|
| 58 |
ds = datasets.load_dataset(dataset_repo_id)
|
| 59 |
|
| 60 |
+
title2qna = {}
|
| 61 |
date2qna = {}
|
| 62 |
longest_qans = 0
|
| 63 |
|
|
|
|
| 85 |
else:
|
| 86 |
date2qna[date] = [data]
|
| 87 |
|
| 88 |
+
for date in date2qna:
|
| 89 |
+
papers = date2qna[date]
|
| 90 |
+
for paper in papers:
|
| 91 |
+
title2qna[paper["title"]] = paper
|
| 92 |
+
|
| 93 |
+
titles = title2qna.keys()
|
| 94 |
+
|
| 95 |
sorted_dates = sorted(date2qna.keys())
|
| 96 |
last_date = sorted_dates[-1]
|
| 97 |
last_papers = date2qna[last_date]
|
|
|
|
| 145 |
gr.Markdown(f"βͺ **(Technical)** {selected_paper['2_additional_breath_q:answers:expert']}"),
|
| 146 |
)
|
| 147 |
|
| 148 |
+
def dumb(title):
|
| 149 |
+
if len(title) > 10:
|
| 150 |
+
return f"{title[:10]}..."
|
| 151 |
+
return title
|
| 152 |
+
|
| 153 |
+
def search(search_in, max_results=3):
|
| 154 |
+
results = []
|
| 155 |
+
|
| 156 |
+
for title in titles:
|
| 157 |
+
if len(results) > 3:
|
| 158 |
+
break
|
| 159 |
+
else:
|
| 160 |
+
if search_in in title:
|
| 161 |
+
results.append(title)
|
| 162 |
+
|
| 163 |
+
return (
|
| 164 |
+
gr.Textbox(
|
| 165 |
+
visible=True if len(results) > 0 else False,
|
| 166 |
+
value=results[0] if len(results) > 0 else ""
|
| 167 |
+
),
|
| 168 |
+
gr.Textbox(
|
| 169 |
+
visible=True if len(results) > 1 else False,
|
| 170 |
+
value=results[1] if len(results) > 1 else ""
|
| 171 |
+
),
|
| 172 |
+
gr.Textbox(
|
| 173 |
+
visible=True if len(results) > 2 else False,
|
| 174 |
+
value=results[2] if len(results) > 2 else ""
|
| 175 |
+
)
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
UPDATE_SEARCH_RESULTS = f"""
|
| 179 |
+
function search(searchIn, maxResults = 3) {{
|
| 180 |
+
if (searchIn.trim().length > 0) {{
|
| 181 |
+
const results = [];
|
| 182 |
+
let titles = {list(titles)};
|
| 183 |
+
|
| 184 |
+
for (const title of titles) {{ // Assuming 'titles' is an array defined elsewhere
|
| 185 |
+
if (results.length > 3) {{
|
| 186 |
+
break;
|
| 187 |
+
}} else {{
|
| 188 |
+
if (title.toLowerCase().includes(searchIn.toLowerCase())) {{ // JavaScript's equivalent to Python's 'in'
|
| 189 |
+
results.push(title);
|
| 190 |
+
}}
|
| 191 |
+
}}
|
| 192 |
+
}}
|
| 193 |
+
|
| 194 |
+
// Handle UI elements (Explanation below)
|
| 195 |
+
const resultElements = [1, 2, 3].map(index => {{
|
| 196 |
+
return results[index - 1] || '';
|
| 197 |
+
}});
|
| 198 |
+
|
| 199 |
+
if (resultElements[0] == '') {{
|
| 200 |
+
document.getElementById('search_r1').style.display = 'none';
|
| 201 |
+
}} else {{
|
| 202 |
+
document.getElementById('search_r1').style.display = 'block';
|
| 203 |
+
}}
|
| 204 |
+
|
| 205 |
+
if (resultElements[1] == '') {{
|
| 206 |
+
document.getElementById('search_r2').style.display = 'none';
|
| 207 |
+
}} else {{
|
| 208 |
+
document.getElementById('search_r2').style.display = 'block';
|
| 209 |
+
}}
|
| 210 |
+
|
| 211 |
+
if (resultElements[2] == '') {{
|
| 212 |
+
document.getElementById('search_r3').style.display = 'none';
|
| 213 |
+
}} else {{
|
| 214 |
+
document.getElementById('search_r3').style.display = 'block';
|
| 215 |
+
}}
|
| 216 |
+
|
| 217 |
+
return resultElements;
|
| 218 |
+
}} else {{
|
| 219 |
+
document.getElementById('search_r1').style.display = 'none';
|
| 220 |
+
document.getElementById('search_r2').style.display = 'none';
|
| 221 |
+
document.getElementById('search_r3').style.display = 'none';
|
| 222 |
+
|
| 223 |
+
return ['', '', '']
|
| 224 |
+
}}
|
| 225 |
+
}}
|
| 226 |
+
"""
|
| 227 |
+
|
| 228 |
+
def set_date(title):
|
| 229 |
+
paper = title2qna[title]
|
| 230 |
+
date = paper["target_date"].strftime("%Y-%m-%d")
|
| 231 |
+
return date
|
| 232 |
+
|
| 233 |
+
def set_papers(date, title):
|
| 234 |
+
papers = [paper["title"] for paper in date2qna[date]]
|
| 235 |
+
return (
|
| 236 |
+
gr.Dropdown(choices=papers, value=title),
|
| 237 |
+
gr.Textbox("")
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
with gr.Blocks(css=STYLE) as demo:
|
| 241 |
+
with gr.Row():
|
| 242 |
+
date_dd = gr.Dropdown(
|
| 243 |
+
sorted_dates,
|
| 244 |
+
value=last_date,
|
| 245 |
+
label="Select date",
|
| 246 |
+
interactive=True,
|
| 247 |
+
scale=3,
|
| 248 |
+
)
|
| 249 |
+
papers_dd = gr.Dropdown(
|
| 250 |
+
[paper["title"] for paper in last_papers],
|
| 251 |
+
value=selected_paper["title"],
|
| 252 |
+
label="Select paper title",
|
| 253 |
+
interactive=True,
|
| 254 |
+
scale=7,
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
with gr.Column(elem_classes=["no-gap"]):
|
| 258 |
+
search_in = gr.Textbox("", placeholder="Enter keywords to search...", elem_id="search_input")
|
| 259 |
+
search_r1 = gr.Button(visible=False, elem_id="search_r1", elem_classes=["no-radius"])
|
| 260 |
+
search_r2 = gr.Button(visible=False, elem_id="search_r2", elem_classes=["no-radius"])
|
| 261 |
+
search_r3 = gr.Button(visible=False, elem_id="search_r3", elem_classes=["no-radius"])
|
| 262 |
+
|
| 263 |
+
search_r1.click(
|
| 264 |
+
set_date,
|
| 265 |
+
search_r1,
|
| 266 |
+
date_dd
|
| 267 |
+
).then(
|
| 268 |
+
set_papers,
|
| 269 |
+
inputs=[date_dd, search_r1],
|
| 270 |
+
outputs=[papers_dd, search_in]
|
| 271 |
)
|
| 272 |
+
|
| 273 |
+
search_r2.click(
|
| 274 |
+
set_date,
|
| 275 |
+
search_r2,
|
| 276 |
+
date_dd
|
| 277 |
+
).then(
|
| 278 |
+
set_papers,
|
| 279 |
+
inputs=[date_dd, search_r2],
|
| 280 |
+
outputs=[papers_dd, search_in]
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
search_r3.click(
|
| 284 |
+
set_date,
|
| 285 |
+
search_r3,
|
| 286 |
+
date_dd
|
| 287 |
+
).then(
|
| 288 |
+
set_papers,
|
| 289 |
+
inputs=[date_dd, search_r3],
|
| 290 |
+
outputs=[papers_dd, search_in]
|
| 291 |
)
|
| 292 |
|
| 293 |
title = gr.Markdown(f"# {selected_paper['title']}")
|
|
|
|
| 366 |
]
|
| 367 |
)
|
| 368 |
|
| 369 |
+
papers_dd.change(
|
| 370 |
set_paper,
|
| 371 |
[date_dd, papers_dd],
|
| 372 |
[
|
|
|
|
| 385 |
]
|
| 386 |
)
|
| 387 |
|
| 388 |
+
search_in.change(
|
| 389 |
+
inputs=[search_in],
|
| 390 |
+
outputs=[search_r1, search_r2, search_r3],
|
| 391 |
+
js=UPDATE_SEARCH_RESULTS,
|
| 392 |
+
fn=None
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
demo.launch(share=True)
|