shibing624 commited on
Commit
467682a
1 Parent(s): c65738a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -20,8 +20,13 @@ sim_model.add_corpus(load_file('corpus.txt'))
20
 
21
  def ai_text(query):
22
  res = sim_model.most_similar(queries=query, topn=5)
23
-
24
- res_show = str(res)
 
 
 
 
 
25
  return res_show
26
 
27
 
@@ -32,12 +37,12 @@ if __name__ == '__main__':
32
  ['她在看书'],
33
  ['一个人弹琴'],
34
  ]
35
-
36
- gr.Interface(ai_text,
37
- inputs=gr.Textbox(label="Enter Query"),
38
- outputs=gr.Textbox(label="Output Box"),
39
- title="Chinese Text Semantic Search Model",
40
- description="Copy or input Chinese text here. Submit and the machine will find the most similarity texts.",
41
- article="Link to <a href='https://github.com/shibing624/similarities' style='color:blue;' target='_blank\'>Github REPO: similarities</a>",
42
- examples=examples
43
- ).launch()
 
20
 
21
  def ai_text(query):
22
  res = sim_model.most_similar(queries=query, topn=5)
23
+ print(res)
24
+ for q_id, c in enumerate(res):
25
+ print('query:', query)
26
+ print("search top 5:")
27
+ print(f'\t{c}')
28
+ res_show = '\n'.join(
29
+ ['search top5:'] + [f'text: {k.get("corpus_doc")} score: {k.get("score"):.4f}' for k in res[0]])
30
  return res_show
31
 
32
 
 
37
  ['她在看书'],
38
  ['一个人弹琴'],
39
  ]
40
+ gr.Interface(
41
+ ai_text,
42
+ inputs=gr.Textbox(lines=2, label="Enter Query"),
43
+ outputs=gr.Textbox(label="Output Box"),
44
+ title="Chinese Text Semantic Search Model",
45
+ description="Copy or input Chinese text here. Submit and the machine will find the most similarity texts.",
46
+ article="Link to <a href='https://github.com/shibing624/similarities' style='color:blue;' target='_blank'>Github REPO</a>",
47
+ examples=examples
48
+ ).launch()