ccm commited on
Commit
ff52d8e
·
verified ·
1 Parent(s): 6bb65a4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -8
main.py CHANGED
@@ -20,8 +20,7 @@ vectors = numpy.stack(data['embedding'].to_list(), axis=0)
20
 
21
  index.add(vectors)
22
 
23
- def search(query):
24
- k=5
25
  query = numpy.expand_dims(model.encode(query), axis=0)
26
  _, I = top_five = index.search(query, k)
27
  top_five = data.loc[I[0]]
@@ -30,16 +29,18 @@ def search(query):
30
  for i in range(k):
31
  search_results += str(i+1) + ". "
32
  search_results += '"' + top_five["bibtex"].values[i]["title"] + '" '
33
- search_results += "_" + top_five["bibtex"].values[i]["citation"] + "_"
34
  if top_five["pub_url"].values[i] is not None:
35
- search_results += " [Full Paper](" + top_five["pub_url"].values[i] + ")"
36
  search_results += "\n"
37
  return search_results
38
 
39
  with gradio.Blocks() as demo:
40
- query = gradio.Textbox(placeholder="Enter search terms...")
41
- btn = gradio.Button("Search")
42
- results = gradio.Markdown()
43
- btn.click(fn=search, inputs=[query], outputs=results)
 
 
44
 
45
  demo.launch(debug=True)
 
20
 
21
  index.add(vectors)
22
 
23
+ def search(query, k):
 
24
  query = numpy.expand_dims(model.encode(query), axis=0)
25
  _, I = top_five = index.search(query, k)
26
  top_five = data.loc[I[0]]
 
29
  for i in range(k):
30
  search_results += str(i+1) + ". "
31
  search_results += '"' + top_five["bibtex"].values[i]["title"] + '" '
32
+ search_results += top_five["bibtex"].values[i]["citation"]
33
  if top_five["pub_url"].values[i] is not None:
34
+ search_results += " [Paper](" + top_five["pub_url"].values[i] + ")"
35
  search_results += "\n"
36
  return search_results
37
 
38
  with gradio.Blocks() as demo:
39
+ with gradio.Group():
40
+ query = gradio.Textbox(placeholder="Enter search terms...", show_label=False, lines=1, max_lines=1)
41
+ with gradio.Accordion("Settings", open=False):
42
+ k = gradio.Number(5.0, label="Number of results", precision=0)
43
+ results = gradio.Markdown()
44
+ query.change(fn=search, inputs=[query, k], outputs=results)
45
 
46
  demo.launch(debug=True)