Team Ai
Apppublic

CodeTed/chinese_spelling_error_correction

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
2likes
app.py30 linesDownload Raw Back to root
1import gradio as gr2from t5.t5_model import T5Model3from transformers import AutoTokenizer, T5ForConditionalGeneration4#tokenizer = AutoTokenizer.from_pretrained("CodeTed/traditional_CSC_t5")5#model = T5ForConditionalGeneration.from_pretrained("CodeTed/traditional_CSC_t5")6model = T5Model('t5', "CodeTed/Chinese_Spelling_Correction_T5", args={"eval_batch_size": 1}, cuda_device=-1, evaluate=True)7 8def cged_correction(sentence = '為了降低少子化,政府可以堆動獎勵生育的政策。'):9    for _ in range(3):10        outputs = model.predict(["糾正句子中的錯字:" + sentence + "_輸出句:"])11        sentence = outputs[0]12    return outputs[0]13 14with gr.Blocks() as demo:15    gr.Markdown(16        """17    # 中文錯別字校正 - Chinese Spelling Correction18    ### Find Spelling Error and get the correction!19    Start typing below to see the correction.20    """21    )22    #設定輸入元件23    sent = gr.Textbox(label="Sentence", placeholder="input the sentence")24    # 設定輸出元件25    output = gr.Textbox(label="Result", placeholder="correction")26    #設定按鈕27    greet_btn = gr.Button("Correction")28    #設定按鈕點選事件29    greet_btn.click(fn=cged_correction, inputs=sent, outputs=output)30demo.launch()