Spaces:
Running
Running
updates
Browse files- requirements.txt +2 -1
- widgets/__init__.py +1 -1
- widgets/body.py +10 -1
- widgets/charts.py +80 -0
requirements.txt
CHANGED
@@ -10,4 +10,5 @@ torch==1.12.1
|
|
10 |
yellowbrick==1.5
|
11 |
transformers==4.22.1
|
12 |
textdistance==4.5.0
|
13 |
-
datasets==2.5.2
|
|
|
|
10 |
yellowbrick==1.5
|
11 |
transformers==4.22.1
|
12 |
textdistance==4.5.0
|
13 |
+
datasets==2.5.2
|
14 |
+
bokeh==2.4.1
|
widgets/__init__.py
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
from .body import render_body
|
2 |
from .sidebar import render_sidebar
|
3 |
-
from .utils import readfile, generate_html_pyecharts
|
|
|
1 |
from .body import render_body
|
2 |
from .sidebar import render_sidebar
|
3 |
+
from .utils import readfile, generate_html_pyecharts
|
widgets/body.py
CHANGED
@@ -5,6 +5,7 @@ from pyecharts.charts import Bar
|
|
5 |
from pyecharts import options as opts
|
6 |
import streamlit.components.v1 as st_render
|
7 |
from .utils import generate_html_pyecharts
|
|
|
8 |
|
9 |
def __preview__(platforms, num_papers, num_papers_preview, query_input,start_year,end_year):
|
10 |
with st.spinner('Searching...'):
|
@@ -36,7 +37,7 @@ We have found following papers for you! (displaying 5 papers for each literature
|
|
36 |
title = str(arxiv[i]['title']).replace('\n', ' ')
|
37 |
publication_year = str(arxiv[i]['published']).replace('\n', ' ')
|
38 |
paperInGeneral_md += f'''|{i + 1}|{title}|{publication_year}|\n'''
|
39 |
-
if '
|
40 |
paperInGeneral_md += '''
|
41 |
## Paper with Code
|
42 |
| ID| Paper Title | Publication Year |
|
@@ -72,6 +73,8 @@ def render_body(platforms, num_papers, num_papers_preview, query_input, show_pre
|
|
72 |
st.markdown(f'''## Clusters Overview''')
|
73 |
st.markdown(f'''Here we show the overview of the clusters, more specifically,''')
|
74 |
st.markdown(f'''\n- the number of papers in each cluster\n- the number of keyphrases of each cluster''')
|
|
|
|
|
75 |
bar = (
|
76 |
Bar()
|
77 |
.add_xaxis([f'Cluster {i + 1}' for i in range(len(clusters))])
|
@@ -80,6 +83,12 @@ def render_body(platforms, num_papers, num_papers_preview, query_input, show_pre
|
|
80 |
)
|
81 |
html = generate_html_pyecharts(bar, 'tmp.html')
|
82 |
st_render.html(html, height=500, width=1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
|
85 |
|
|
|
5 |
from pyecharts import options as opts
|
6 |
import streamlit.components.v1 as st_render
|
7 |
from .utils import generate_html_pyecharts
|
8 |
+
from .charts import build_bar_charts
|
9 |
|
10 |
def __preview__(platforms, num_papers, num_papers_preview, query_input,start_year,end_year):
|
11 |
with st.spinner('Searching...'):
|
|
|
37 |
title = str(arxiv[i]['title']).replace('\n', ' ')
|
38 |
publication_year = str(arxiv[i]['published']).replace('\n', ' ')
|
39 |
paperInGeneral_md += f'''|{i + 1}|{title}|{publication_year}|\n'''
|
40 |
+
if 'Paper with Code' in platforms:
|
41 |
paperInGeneral_md += '''
|
42 |
## Paper with Code
|
43 |
| ID| Paper Title | Publication Year |
|
|
|
73 |
st.markdown(f'''## Clusters Overview''')
|
74 |
st.markdown(f'''Here we show the overview of the clusters, more specifically,''')
|
75 |
st.markdown(f'''\n- the number of papers in each cluster\n- the number of keyphrases of each cluster''')
|
76 |
+
'''
|
77 |
+
plot using pyecharts
|
78 |
bar = (
|
79 |
Bar()
|
80 |
.add_xaxis([f'Cluster {i + 1}' for i in range(len(clusters))])
|
|
|
83 |
)
|
84 |
html = generate_html_pyecharts(bar, 'tmp.html')
|
85 |
st_render.html(html, height=500, width=1000)
|
86 |
+
'''
|
87 |
+
st.bokeh_chart(build_bar_charts(
|
88 |
+
x_range=[f'Cluster {i + 1}' for i in range(len(clusters))],
|
89 |
+
y_names= ['Number of Papers', 'Number of Keyphrases'],
|
90 |
+
y_data=[[len(c) for c in clusters],[len(c.get_keyphrases()) for c in clusters]]
|
91 |
+
))
|
92 |
|
93 |
|
94 |
|
widgets/charts.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
from bokeh.models import ColumnDataSource
|
3 |
+
from bokeh.plotting import figure
|
4 |
+
from bokeh.transform import dodge
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
COLORS = [
|
8 |
+
'#FE2D01',
|
9 |
+
'#016CFE',
|
10 |
+
'#FEB101',
|
11 |
+
'#FE018B',
|
12 |
+
'#AAB7B8',
|
13 |
+
'#212F3D'
|
14 |
+
]
|
15 |
+
|
16 |
+
'''
|
17 |
+
clusters = ['Cluster 1', 'C 2', 'C 3', 'Plums', 'Grapes', 'Strawberries']
|
18 |
+
years = ['number of papers', 'number of keyphrases', ]
|
19 |
+
|
20 |
+
data = {'clusters': clusters,
|
21 |
+
f'{years[0]}': [2, 1, 4, 3, 2, 4],
|
22 |
+
f'{years[1]}': [5, 3, 3, 2, 4, 6],
|
23 |
+
}
|
24 |
+
|
25 |
+
source = ColumnDataSource(data=data)
|
26 |
+
|
27 |
+
p = figure(x_range=clusters, title="Fruit counts by year",
|
28 |
+
toolbar_location=None, tools="")
|
29 |
+
|
30 |
+
p.vbar(x=dodge('clusters', -0.25, range=p.x_range), top=f'{years[0]}', width=0.2, source=source,
|
31 |
+
color="#c9d9d3", legend_label="2015")
|
32 |
+
|
33 |
+
p.vbar(x=dodge('clusters', 0.0, range=p.x_range), top=f'{years[1]}', width=0.2, source=source,
|
34 |
+
color="#718dbf", legend_label="2016")
|
35 |
+
|
36 |
+
|
37 |
+
p.x_range.range_padding = 0.1
|
38 |
+
p.xgrid.grid_line_color = None
|
39 |
+
p.legend.location = "top_left"
|
40 |
+
p.legend.orientation = "horizontal"
|
41 |
+
'''
|
42 |
+
|
43 |
+
|
44 |
+
def build_bar_charts(x_range: List, y_names: List[str], y_data = List[List]):
|
45 |
+
valid_y = lambda x: len(x) == len(x_range)
|
46 |
+
if not (len(y_names) == len(y_data) and all(map(valid_y,y_data))):
|
47 |
+
raise RuntimeError('The data shapes are not aligned.')
|
48 |
+
|
49 |
+
|
50 |
+
if len(y_names) % 2 == 0:
|
51 |
+
offsets = [-0.125 - 0.25*(i-1) for i in range(len(y_names)//2,0,-1)]
|
52 |
+
offsets += [0.125 + 0.25*(i) for i in range(len(y_names)//2)]
|
53 |
+
else:
|
54 |
+
offsets = [-0.25 * i for i in range(len(y_names)//2,0,-1)]
|
55 |
+
offsets.append(0)
|
56 |
+
offsets += [0.25* (i+1) for i in range(len(y_names)//2)]
|
57 |
+
|
58 |
+
data = {
|
59 |
+
'x': x_range
|
60 |
+
}
|
61 |
+
for i,y in enumerate(y_data):
|
62 |
+
data[f'y{i}'] = y
|
63 |
+
source = ColumnDataSource(data)
|
64 |
+
p = figure(x_range=x_range,
|
65 |
+
tools = "box_zoom,save,reset",
|
66 |
+
height=500,
|
67 |
+
y_range=(0,np.max(y_data)+10)
|
68 |
+
)
|
69 |
+
|
70 |
+
for i,y in enumerate(y_data):
|
71 |
+
p.vbar(x=dodge('x', offsets[i], range=p.x_range), top=f'y{i}', width=0.2, source=source,
|
72 |
+
color=COLORS[i], legend_label=y_names[i])
|
73 |
+
|
74 |
+
p.x_range.range_padding = 0.1
|
75 |
+
p.xgrid.grid_line_color = None
|
76 |
+
p.legend.location = "top_left"
|
77 |
+
p.legend.orientation = "horizontal"
|
78 |
+
|
79 |
+
return p
|
80 |
+
|