chansung commited on
Commit
16272b2
β€’
1 Parent(s): 3993884

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -112
app.py CHANGED
@@ -20,6 +20,7 @@ from paper.download import (
20
  from paper.parser import extract_text_and_figures
21
  from gen.gemini import get_basic_qa, get_deep_qa
22
  from constants.styles import STYLE
 
23
 
24
  from apscheduler.schedulers.background import BackgroundScheduler
25
 
@@ -321,117 +322,6 @@ def search(search_in, max_results=3):
321
  )
322
  )
323
 
324
- UPDATE_SEARCH_RESULTS = f"""
325
- function search(searchIn, maxResults = 3) {{
326
- if (searchIn.trim().length > 0) {{
327
- const results = [];
328
- let titles = {list(titles)};
329
-
330
- for (const title of titles) {{ // Assuming 'titles' is an array defined elsewhere
331
- if (results.length > 10) {{
332
- break;
333
- }} else {{
334
- if (title.toLowerCase().includes(searchIn.toLowerCase())) {{ // JavaScript's equivalent to Python's 'in'
335
- results.push(title);
336
- }}
337
- }}
338
- }}
339
-
340
- // Handle UI elements (Explanation below)
341
- const resultElements = [1,2,3,4,5,6,7,8,9,10].map(index => {{
342
- return results[index - 1] || '';
343
- }});
344
-
345
- if (resultElements[0] == '') {{
346
- document.getElementById('search_r1').style.display = 'none';
347
- }} else {{
348
- document.getElementById('search_r1').style.display = 'block';
349
- }}
350
-
351
- if (resultElements[1] == '') {{
352
- document.getElementById('search_r2').style.display = 'none';
353
- }} else {{
354
- document.getElementById('search_r2').style.display = 'block';
355
- }}
356
-
357
- if (resultElements[2] == '') {{
358
- document.getElementById('search_r3').style.display = 'none';
359
- }} else {{
360
- document.getElementById('search_r3').style.display = 'block';
361
- }}
362
-
363
- if (resultElements[3] == '') {{
364
- document.getElementById('search_r4').style.display = 'none';
365
- }} else {{
366
- document.getElementById('search_r4').style.display = 'block';
367
- }}
368
-
369
- if (resultElements[4] == '') {{
370
- document.getElementById('search_r5').style.display = 'none';
371
- }} else {{
372
- document.getElementById('search_r5').style.display = 'block';
373
- }}
374
-
375
- if (resultElements[5] == '') {{
376
- document.getElementById('search_r6').style.display = 'none';
377
- }} else {{
378
- document.getElementById('search_r6').style.display = 'block';
379
- }}
380
-
381
- if (resultElements[6] == '') {{
382
- document.getElementById('search_r7').style.display = 'none';
383
- }} else {{
384
- document.getElementById('search_r7').style.display = 'block';
385
- }}
386
-
387
- if (resultElements[7] == '') {{
388
- document.getElementById('search_r8').style.display = 'none';
389
- }} else {{
390
- document.getElementById('search_r8').style.display = 'block';
391
- }}
392
-
393
- if (resultElements[8] == '') {{
394
- document.getElementById('search_r9').style.display = 'none';
395
- }} else {{
396
- document.getElementById('search_r9').style.display = 'block';
397
- }}
398
-
399
- if (resultElements[9] == '') {{
400
- document.getElementById('search_r10').style.display = 'none';
401
- }} else {{
402
- document.getElementById('search_r10').style.display = 'block';
403
- }}
404
-
405
- return resultElements;
406
- }} else {{
407
- document.getElementById('search_r1').style.display = 'none';
408
- document.getElementById('search_r2').style.display = 'none';
409
- document.getElementById('search_r3').style.display = 'none';
410
- document.getElementById('search_r4').style.display = 'none';
411
- document.getElementById('search_r5').style.display = 'none';
412
- document.getElementById('search_r6').style.display = 'none';
413
- document.getElementById('search_r7').style.display = 'none';
414
- document.getElementById('search_r8').style.display = 'none';
415
- document.getElementById('search_r9').style.display = 'none';
416
- document.getElementById('search_r10').style.display = 'none';
417
-
418
- return ['', '', '', '', '', '', '', '', '', '']
419
- }}
420
- }}
421
- """
422
-
423
- UPDATE_IF_TYPE = f"""
424
- function chage_if_type(if_type) {{
425
- if (if_type == 'Q&As') {{
426
- document.getElementById('chat_block').style.display = 'none';
427
- document.getElementById('qna_block').style.display = 'block';
428
- }} else {{
429
- document.getElementById('chat_block').style.display = 'block';
430
- document.getElementById('qna_block').style.display = 'none';
431
- }}
432
- }}
433
- """
434
-
435
  def set_date(title):
436
  paper = title2qna[title]
437
  date = paper["target_date"].strftime("%Y-%m-%d")
@@ -666,7 +556,7 @@ with gr.Blocks(css=STYLE, theme=gr.themes.Soft()) as demo:
666
  search_r1, search_r2, search_r3, search_r4, search_r5,
667
  search_r6, search_r7, search_r8, search_r9, search_r10
668
  ],
669
- js=UPDATE_SEARCH_RESULTS,
670
  fn=None
671
  )
672
 
 
20
  from paper.parser import extract_text_and_figures
21
  from gen.gemini import get_basic_qa, get_deep_qa
22
  from constants.styles import STYLE
23
+ from constants.js import UPDATE_SEARCH_RESULTS, UPDATE_IF_TYPE
24
 
25
  from apscheduler.schedulers.background import BackgroundScheduler
26
 
 
322
  )
323
  )
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  def set_date(title):
326
  paper = title2qna[title]
327
  date = paper["target_date"].strftime("%Y-%m-%d")
 
556
  search_r1, search_r2, search_r3, search_r4, search_r5,
557
  search_r6, search_r7, search_r8, search_r9, search_r10
558
  ],
559
+ js=UPDATE_SEARCH_RESULTS % str(list(titles)),
560
  fn=None
561
  )
562