From 8be24dae43185cb681766135329338deb4dd4349 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Tue, 16 Nov 2021 21:39:43 -0800 Subject: [PATCH] allow for full sorting, slice and dicing with all options in the UI, and the previous shortcuts. now have a lot more flexibility to slice and dice as desired --- serve.py | 22 ++++++++++------- static/paper_list.js | 2 +- static/style.css | 12 ++++++++++ templates/index.html | 57 ++++++++++++++++++++++++++++++++++---------- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/serve.py b/serve.py index 51f8c2c..7891057 100644 --- a/serve.py +++ b/serve.py @@ -82,11 +82,11 @@ def time_rank(): scores = [(tnow - v['_time'])/60/60/24 for k, v in ms] # time delta in days return pids, scores -def svm_rank(tags=None, pid=None): +def svm_rank(tags: str = '', pid: str = ''): # tag can be one tag or a few comma-separated tags or 'all' for all tags we have in db # pid can be a specific paper id to set as positive for a kind of nearest neighbor search - assert (tags is not None) or (pid is not None) + assert tags or pid # load all of the features features = pickle.load(open('features.p', 'rb')) @@ -99,9 +99,9 @@ def svm_rank(tags=None, pid=None): # construct the positive set y = np.zeros(n, dtype=np.float32) - if pid is not None: + if pid: y[ptoi[pid]] = 1.0 - elif tags is not None: + elif tags: tags_db = get_tags() tags_filter_to = tags_db.keys() if tags == 'all' else set(tags.split(',')) for tag, pids in tags_db.items(): @@ -133,7 +133,7 @@ def default_context(papers, **kwargs): gvars = {} gvars['search_query'] = '' gvars['time_filter'] = '' - gvars['message'] = 'default_message' + gvars['message'] = '' context['gvars'] = gvars return context @@ -154,14 +154,16 @@ def main(): # GET options opt_rank = request.args.get('rank', 'time') # rank type. tags|pid|time|random - opt_tags = request.args.get('tags', 'all') # tags to rank by if opt_rank == 'tag' - opt_pid = request.args.get('pid', None) # pid to find nearest neighbors to + opt_tags = request.args.get('tags', '') # tags to rank by if opt_rank == 'tag' + opt_pid = request.args.get('pid', '') # pid to find nearest neighbors to opt_time_filter = request.args.get('time_filter', '') # number of days to filter by opt_skip_have = request.args.get('skip_have', 'no') # hide papers we already have? # rank papers: by tags, by time, by random - if opt_rank in ['tags', 'pid']: - pids, scores = svm_rank(tags=opt_tags, pid=opt_pid) + if opt_rank == 'tags': + pids, scores = svm_rank(tags=opt_tags) + elif opt_rank == 'pid': + pids, scores = svm_rank(pid=opt_pid) elif opt_rank == 'time': pids, scores = time_rank() elif opt_rank == 'random': @@ -193,7 +195,9 @@ def main(): context = default_context(papers) context['gvars']['rank'] = opt_rank context['gvars']['tags'] = opt_tags + context['gvars']['pid'] = opt_pid context['gvars']['time_filter'] = opt_time_filter + context['gvars']['skip_have'] = opt_skip_have return render_template('index.html', **context) diff --git a/static/paper_list.js b/static/paper_list.js index ca94423..fe69ae9 100644 --- a/static/paper_list.js +++ b/static/paper_list.js @@ -19,7 +19,7 @@ const Paper = props => { const subber = () => fetch("/sub/" + p.id + "/" + prompt("tag to subtract from this paper:")) .then(response => console.log(response.text())); const utags = p.utags.map((utxt, ix) => ); - const similar_url = "/?rank=tags&pid=" + p.id; + const similar_url = "/?rank=pid&pid=" + p.id; return (
{p.weight.toFixed(2)}
diff --git a/static/style.css b/static/style.css index cffb11d..306913d 100644 --- a/static/style.css +++ b/static/style.css @@ -124,3 +124,15 @@ body { background-position: left center; outline: 0; } +#cbox { + margin-top: 5px; + font-size: 14px; +} +#cbox_fast { + font-size: 14px; +} +#cbox_fast a { + display: inline-block; + background-color: #eee; + padding: 3px; +} diff --git a/templates/index.html b/templates/index.html index 66b149d..7a8205c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -26,27 +26,60 @@ var gvars = {{ gvars | tojson }};
+ +
+ +
- - recommend over last week
- recommend over last 3 days
- recent
- random last week
+
+ + + + + + + + + + + + + + + + + + + + + + +
+
+ +
- +
{{gvars.message}}