|
import gradio as gr |
|
from transformers import AutoTokenizer, T5ForConditionalGeneration |
|
tokenizer = AutoTokenizer.from_pretrained("CodeTed/traditional_CSC_t5") |
|
model = T5ForConditionalGeneration.from_pretrained("CodeTed/traditional_CSC_t5") |
|
|
|
|
|
def cged_correction(sentence = '為了降低少子化,政府可以堆動獎勵生育的政策。'): |
|
input_ids = tokenizer('糾正句子裡的錯字:' + sentence + "_輸出句:", return_tensors="pt").input_ids |
|
outputs = model.generate(input_ids, max_length=200) |
|
edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
return edited_text |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown( |
|
""" |
|
# Flip Text! |
|
Start typing below to see the output. |
|
""" |
|
) |
|
|
|
sent = gr.Textbox(label="Sentence") |
|
|
|
output = gr.Textbox(label="Result") |
|
|
|
greet_btn = gr.Button("Correction") |
|
|
|
greet_btn.click(fn=cged_correction, inputs=sent, outputs=output) |
|
demo.launch() |