File size: 3,831 Bytes
9420338
 
469542a
b2495e2
 
 
 
9420338
68c1b6b
 
 
 
9420338
 
68c1b6b
 
9420338
 
 
68c1b6b
 
 
 
 
 
 
 
 
9420338
 
 
 
68c1b6b
 
 
 
 
 
 
 
9420338
 
 
 
68c1b6b
 
 
 
 
 
 
 
9420338
469542a
68c1b6b
 
 
 
469542a
 
68c1b6b
 
469542a
 
 
b2495e2
 
469542a
436e5a1
b2495e2
 
 
 
 
 
 
 
 
 
 
 
 
 
469542a
 
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
import streamlit as st
from api_ import ArxivQuery, IEEEQuery, PaperWithCodeQuery
from lrt_instance import *
from pyecharts.charts import Bar
from pyecharts import options as opts
import streamlit.components.v1 as st_render
from .utils import generate_html_pyecharts

def __preview__(platforms, num_papers, num_papers_preview, query_input,start_year,end_year):
    with st.spinner('Searching...'):
        paperInGeneral = st.empty()  # paper的大概
        paperInGeneral_md = '''# Query Results Preview
We have found following papers for you! (displaying 5 papers for each literature platforms)
'''
        if 'IEEE' in platforms:
            paperInGeneral_md += '''## IEEE
| ID| Paper Title | Publication Year |
| -------- | -------- | -------- |
'''
            IEEEQuery.__setup_api_key__('vpd9yy325enruv27zj2d353e')
            ieee = IEEEQuery.query(query_input,start_year,end_year,num_papers)
            num_papers_preview = min(len(ieee), num_papers_preview)
            for i in range(num_papers_preview):
                title = str(ieee[i]['title']).replace('\n', ' ')
                publication_year = str(ieee[i]['publication_year']).replace('\n', ' ')
                paperInGeneral_md += f'''|{i + 1}|{title}|{publication_year}|\n'''
        if 'Arxiv' in platforms:
            paperInGeneral_md += '''
## Arxiv
| ID| Paper Title | Publication Year |
| -------- | -------- | -------- |
'''
            arxiv = ArxivQuery.query(query_input, max_results=num_papers)
            num_papers_preview = min(len(arxiv), num_papers_preview)
            for i in range(num_papers_preview):
                title = str(arxiv[i]['title']).replace('\n', ' ')
                publication_year = str(arxiv[i]['published']).replace('\n', ' ')
                paperInGeneral_md += f'''|{i + 1}|{title}|{publication_year}|\n'''
        if 'PaperWithCode' in platforms:
            paperInGeneral_md += '''
## Paper with Code
| ID| Paper Title | Publication Year |
| -------- | -------- | -------- |
'''
            pwc = PaperWithCodeQuery.query(query_input, items_per_page=num_papers)
            num_papers_preview = min(len(pwc), num_papers_preview)
            for i in range(num_papers_preview):
                title = str(pwc[i]['title']).replace('\n', ' ')
                publication_year = str(pwc[i]['published']).replace('\n', ' ')
                paperInGeneral_md += f'''|{i + 1}|{title}|{publication_year}|\n'''

        paperInGeneral.markdown(paperInGeneral_md)

def render_body(platforms, num_papers, num_papers_preview, query_input, show_preview:bool,start_year,end_year,k):

    tmp = st.empty()
    if query_input != '':
        tmp.markdown(f'You entered query: `{query_input}`')

        # preview
        if show_preview:
            __preview__(platforms,num_papers,num_papers_preview,query_input,start_year,end_year)


        # lrt results
        generator =  baseline_lrt(query_input,num_papers,start_year,end_year,platforms, best_k=k)
        for i,plat in enumerate(platforms):
            clusters, articles = next(generator)
            st.markdown(f'''# {plat} Results''')
            clusters.sort()

            st.markdown(f'''## Clusters Overview''')
            st.markdown(f'''Here we show the overview of the clusters, more specifically,''')
            st.markdown(f'''\n- the number of papers in each cluster\n- the number of keyphrases of each cluster''')
            bar = (
                Bar()
                .add_xaxis([f'Cluster {i + 1}' for i in range(len(clusters))])
                .add_yaxis("number of papers", [len(c) for c in clusters])
                .add_yaxis("number of keyphrases", [len(c.get_keyphrases()) for c in clusters])
            )
            html = generate_html_pyecharts(bar, 'tmp.html')
            st_render.html(html, height=500, width=1000)