Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,13 +22,14 @@ def create_miread_embed(sents, bundle):
|
|
22 |
return feature.cpu()
|
23 |
|
24 |
|
25 |
-
def get_matches(query
|
26 |
-
matches = vecdb.similarity_search_with_score(query, k=
|
27 |
return matches
|
28 |
|
29 |
|
30 |
-
def inference(query
|
31 |
-
matches = get_matches(query
|
|
|
32 |
j_bucket = {}
|
33 |
n_table = []
|
34 |
a_table = []
|
@@ -38,7 +39,7 @@ def inference(query, k=30):
|
|
38 |
def normaliser(x): return round(1 - (x-min_score)/max_score, 3)
|
39 |
for i, match in enumerate(matches):
|
40 |
doc = match[0]
|
41 |
-
score = round(normaliser(round(match[1].item(), 3)),3)
|
42 |
title = doc.metadata['title']
|
43 |
author = doc.metadata['authors'][0].title()
|
44 |
date = doc.metadata.get('date', 'None')
|
@@ -46,7 +47,7 @@ def inference(query, k=30):
|
|
46 |
submitter = doc.metadata.get('submitter', 'None')
|
47 |
# journal = doc.metadata.get('journal', 'None').strip()
|
48 |
journal = doc.metadata['journal']
|
49 |
-
if (journal
|
50 |
journal = 'None'
|
51 |
else:
|
52 |
journal = journal.strip()
|
@@ -63,7 +64,12 @@ def inference(query, k=30):
|
|
63 |
title,
|
64 |
link,
|
65 |
date]
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# For abstracts
|
69 |
record = [i+1,
|
@@ -78,8 +84,8 @@ def inference(query, k=30):
|
|
78 |
a_table.append(record)
|
79 |
|
80 |
del j_bucket['None']
|
81 |
-
j_table = sorted([[journal, round(score,3)] for journal,
|
82 |
-
score in j_bucket.items()],
|
83 |
key=lambda x: x[1], reverse=True)
|
84 |
j_table = [[i+1, item[0], item[1]] for i, item in enumerate(j_table)]
|
85 |
j_output = gr.Dataframe.update(value=j_table, visible=True)
|
@@ -111,9 +117,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
111 |
|
112 |
abst = gr.Textbox(label="Abstract", lines=10)
|
113 |
|
114 |
-
k = gr.Slider(1, 100, step=1, value=50,
|
115 |
-
label="Number of matches to consider")
|
116 |
-
|
117 |
action_btn = gr.Button(value="Find Matches")
|
118 |
|
119 |
with gr.Tab("Authors"):
|
@@ -146,7 +149,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
146 |
action_btn.click(fn=inference,
|
147 |
inputs=[
|
148 |
abst,
|
149 |
-
k,
|
150 |
],
|
151 |
outputs=[a_output, j_output, n_output],
|
152 |
api_name="neurojane")
|
|
|
22 |
return feature.cpu()
|
23 |
|
24 |
|
25 |
+
def get_matches(query):
|
26 |
+
matches = vecdb.similarity_search_with_score(query, k=60)
|
27 |
return matches
|
28 |
|
29 |
|
30 |
+
def inference(query):
|
31 |
+
matches = get_matches(query)
|
32 |
+
auth_counts = {}
|
33 |
j_bucket = {}
|
34 |
n_table = []
|
35 |
a_table = []
|
|
|
39 |
def normaliser(x): return round(1 - (x-min_score)/max_score, 3)
|
40 |
for i, match in enumerate(matches):
|
41 |
doc = match[0]
|
42 |
+
score = round(normaliser(round(match[1].item(), 3)), 3)
|
43 |
title = doc.metadata['title']
|
44 |
author = doc.metadata['authors'][0].title()
|
45 |
date = doc.metadata.get('date', 'None')
|
|
|
47 |
submitter = doc.metadata.get('submitter', 'None')
|
48 |
# journal = doc.metadata.get('journal', 'None').strip()
|
49 |
journal = doc.metadata['journal']
|
50 |
+
if (journal is None or journal.strip() == ''):
|
51 |
journal = 'None'
|
52 |
else:
|
53 |
journal = journal.strip()
|
|
|
64 |
title,
|
65 |
link,
|
66 |
date]
|
67 |
+
if auth_counts.get(author, 0) < 2:
|
68 |
+
n_table.append(record)
|
69 |
+
if auth_counts.get(author, 0) == 0:
|
70 |
+
auth_counts[author] = 1
|
71 |
+
else:
|
72 |
+
auth_counts[author] += 1
|
73 |
|
74 |
# For abstracts
|
75 |
record = [i+1,
|
|
|
84 |
a_table.append(record)
|
85 |
|
86 |
del j_bucket['None']
|
87 |
+
j_table = sorted([[journal, round(score, 3)] for journal,
|
88 |
+
score in j_bucket.items()],
|
89 |
key=lambda x: x[1], reverse=True)
|
90 |
j_table = [[i+1, item[0], item[1]] for i, item in enumerate(j_table)]
|
91 |
j_output = gr.Dataframe.update(value=j_table, visible=True)
|
|
|
117 |
|
118 |
abst = gr.Textbox(label="Abstract", lines=10)
|
119 |
|
|
|
|
|
|
|
120 |
action_btn = gr.Button(value="Find Matches")
|
121 |
|
122 |
with gr.Tab("Authors"):
|
|
|
149 |
action_btn.click(fn=inference,
|
150 |
inputs=[
|
151 |
abst,
|
|
|
152 |
],
|
153 |
outputs=[a_output, j_output, n_output],
|
154 |
api_name="neurojane")
|