Spaces:
Running
Running
# -*- coding: utf-8 -*- | |
""" | |
@author:XuMing(xuming624@qq.com) | |
@description: | |
""" | |
import gradio as gr | |
from text2vec import SBert, cos_sim, semantic_search, Similarity | |
# 中文句向量模型(CoSENT) | |
sim_model = Similarity(model_name_or_path='shibing624/text2vec-base-chinese', | |
similarity_type='cosine', embedding_type='sbert') | |
sentences1 = ['如何更换花呗绑定银行卡', | |
'The cat sits outside', | |
'A man is playing guitar', | |
'The new movie is awesome'] | |
sentences2 = ['花呗更改绑定银行卡', | |
'The dog plays in the garden', | |
'A woman watches TV', | |
'The new movie is so great'] | |
def ai_text(sentence1, sentence2): | |
score = sim_model.get_score(sentence1, sentence2) | |
print("{} \t\t {} \t\t Score: {:.4f}".format(sentence1, sentence2, score)) | |
return score | |
if __name__ == '__main__': | |
examples = [ | |
['import torch.nn as'], | |
['parser.add_argument("--num_train_epochs",'], | |
['torch.device('], | |
['def set_seed('], | |
] | |
input1 = gr.inputs.Textbox(placeholder="Enter First Sentence") | |
input2 = gr.inputs.Textbox(placeholder="Enter Second Sentence") | |
output_text = gr.outputs.Textbox() | |
gr.Interface(ai_text, | |
inputs=[input1, input2], | |
outputs=[output_text], | |
theme="grass", | |
title="Chinese Text to Vector Model shibing624/text2vec-base-chinese", | |
description="Copy or input python code here. Submit and the machine will calculate the cosine score.", | |
article="Link to <a href='https://github.com/shibing624/text2vec' style='color:blue;' target='_blank\'>Github REPO</a>", | |
# examples=examples | |
).launch() |