shibing624 commited on
Commit
5b34b0f
1 Parent(s): e29010d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -21
app.py CHANGED
@@ -1,25 +1,16 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
  @author:XuMing([email protected])
4
- @description:
5
  """
6
  import gradio as gr
7
- from text2vec import SBert, cos_sim, semantic_search, Similarity
8
 
9
  # 中文句向量模型(CoSENT)
10
  sim_model = Similarity(model_name_or_path='shibing624/text2vec-base-chinese',
11
- similarity_type='cosine', embedding_type='sbert')
12
 
13
 
14
- sentences1 = ['如何更换花呗绑定银行卡',
15
- 'The cat sits outside',
16
- 'A man is playing guitar',
17
- 'The new movie is awesome']
18
-
19
- sentences2 = ['花呗更改绑定银行卡',
20
- 'The dog plays in the garden',
21
- 'A woman watches TV',
22
- 'The new movie is so great']
23
  def ai_text(sentence1, sentence2):
24
  score = sim_model.get_score(sentence1, sentence2)
25
  print("{} \t\t {} \t\t Score: {:.4f}".format(sentence1, sentence2, score))
@@ -29,13 +20,13 @@ def ai_text(sentence1, sentence2):
29
 
30
  if __name__ == '__main__':
31
  examples = [
32
- ['import torch.nn as'],
33
- ['parser.add_argument("--num_train_epochs",'],
34
- ['torch.device('],
35
- ['def set_seed('],
36
  ]
37
- input1 = gr.inputs.Textbox(placeholder="Enter First Sentence")
38
- input2 = gr.inputs.Textbox(placeholder="Enter Second Sentence")
39
 
40
  output_text = gr.outputs.Textbox()
41
  gr.Interface(ai_text,
@@ -43,7 +34,7 @@ if __name__ == '__main__':
43
  outputs=[output_text],
44
  theme="grass",
45
  title="Chinese Text to Vector Model shibing624/text2vec-base-chinese",
46
- description="Copy or input python code here. Submit and the machine will calculate the cosine score.",
47
  article="Link to <a href='https://github.com/shibing624/text2vec' style='color:blue;' target='_blank\'>Github REPO</a>",
48
- # examples=examples
49
- ).launch()
 
1
  # -*- coding: utf-8 -*-
2
  """
3
  @author:XuMing([email protected])
4
+ @description: text similarity example, fine-tuned by CoSENT model
5
  """
6
  import gradio as gr
7
+ from text2vec import Similarity
8
 
9
  # 中文句向量模型(CoSENT)
10
  sim_model = Similarity(model_name_or_path='shibing624/text2vec-base-chinese',
11
+ similarity_type='cosine', embedding_type='sbert')
12
 
13
 
 
 
 
 
 
 
 
 
 
14
  def ai_text(sentence1, sentence2):
15
  score = sim_model.get_score(sentence1, sentence2)
16
  print("{} \t\t {} \t\t Score: {:.4f}".format(sentence1, sentence2, score))
 
20
 
21
  if __name__ == '__main__':
22
  examples = [
23
+ ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡'],
24
+ ['我在北京打篮球', '我是北京人,我喜欢篮球'],
25
+ ['一个女人在看书。', '一个女人在揉面团'],
26
+ ['一个男人在车库里举重。', '一个人在举重。'],
27
  ]
28
+ input1 = gr.inputs.Textbox(lines=2, placeholder="Enter First Sentence")
29
+ input2 = gr.inputs.Textbox(lines=2, placeholder="Enter Second Sentence")
30
 
31
  output_text = gr.outputs.Textbox()
32
  gr.Interface(ai_text,
 
34
  outputs=[output_text],
35
  theme="grass",
36
  title="Chinese Text to Vector Model shibing624/text2vec-base-chinese",
37
+ description="Copy or input Chinese text here. Submit and the machine will calculate the cosine score.",
38
  article="Link to <a href='https://github.com/shibing624/text2vec' style='color:blue;' target='_blank\'>Github REPO</a>",
39
+ examples=examples
40
+ ).launch()