Spaces:
Runtime error
Runtime error
shibing624
commited on
Commit
·
827a4f5
1
Parent(s):
a10f389
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
26 |
+
|
27 |
+
return score
|
28 |
+
|
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,
|
42 |
+
inputs=[input1, input2],
|
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()
|