Spaces:
Running
Running
| # !/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| # @time : 2021/2/29 21:41 | |
| # @author : Mo | |
| # @function: transformers直接加载bert类模型测试 | |
| import traceback | |
| import time | |
| import sys | |
| import os | |
| os.environ["MACRO_CORRECT_FLAG_CSC_TOKEN"] = "1" | |
| os.environ["CUDA_VISIBLE_DEVICES"] = "-1" | |
| os.environ["USE_TORCH"] = "1" | |
| from macro_correct.pytorch_textcorrection.tcTools import cut_sent_by_stay | |
| from macro_correct import correct_basic | |
| from macro_correct import correct_long | |
| from macro_correct import correct | |
| import gradio as gr | |
| # pretrained_model_name_or_path = "shibing624/macbert4csc-base-chinese" | |
| pretrained_model_name_or_path = "Macadam/macbert4mdcspell_v2" | |
| # pretrained_model_name_or_path = "Macropodus/macbert4mdcspell_v1" | |
| # pretrained_model_name_or_path = "Macropodus/macbert4csc_v1" | |
| # pretrained_model_name_or_path = "Macropodus/macbert4csc_v2" | |
| # pretrained_model_name_or_path = "Macropodus/bert4csc_v1" | |
| # device = torch.device("cpu") | |
| # device = torch.device("cuda") | |
| def macro_correct(text): | |
| print(text) | |
| text_csc = correct_long(text) | |
| print(text_csc) | |
| print("#"*128) | |
| text_out = "" | |
| for t in text_csc: | |
| for k, v in t.items(): | |
| text_out += f"{k}: {v}\n" | |
| text_out += "\n" | |
| return text_out | |
| if __name__ == '__main__': | |
| print(macro_correct('少先队员因该为老人让坐')) | |
| examples = [ | |
| "机七学习是人工智能领遇最能体现智能的一个分知", | |
| "我是练习时长两念半的鸽仁练习生蔡徐坤", | |
| "真麻烦你了。希望你们好好的跳无", | |
| "他法语说的很好,的语也不错", | |
| "遇到一位很棒的奴生跟我疗天", | |
| "我们为这个目标努力不解", | |
| ] | |
| gr.Interface( | |
| macro_correct, | |
| inputs='text', | |
| outputs='text', | |
| title="Chinese Spelling Correction Model Macropodus/macbert4csc_v2", | |
| description="Copy or input error Chinese text. Submit and the machine will correct text.", | |
| article="Link to <a href='https://github.com/yongzhuo/macro-correct' style='color:blue;' target='_blank\'>Github REPO: macro-correct</a>", | |
| examples=examples | |
| ).launch() | |
| # ).launch(server_name="0.0.0.0", server_port=8066, share=False, debug=True) | |