TedYeh commited on
Commit
c1d5d90
1 Parent(s): ea268c4

update app

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -3,9 +3,10 @@ from transformers import AutoTokenizer, T5ForConditionalGeneration
3
  tokenizer = AutoTokenizer.from_pretrained("CodeTed/CGEDit")
4
  model = T5ForConditionalGeneration.from_pretrained("CodeTed/CGEDit")
5
 
6
-
7
  def cged_correction(sentence, function):
8
- input_ids = tokenizer('糾正句子裡的錯字:' + sentence, return_tensors="pt").input_ids
 
 
9
  outputs = model.generate(input_ids, max_length=200)
10
  edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
11
  return edited_text
@@ -13,12 +14,12 @@ def cged_correction(sentence, function):
13
  with gr.Blocks() as demo:
14
  gr.Markdown(
15
  """
16
- # 中文錯別字校正 - Chinese Spelling Correction
17
- ### Find Spelling Error and get the correction!
18
  Start typing below to see the correction.
19
  """
20
  )
21
- funt = gr.Radio(["add", "subtract", "multiply", "divide"])
22
  #設定輸入元件
23
  sent = gr.Textbox(label="Sentence", placeholder="input the sentence")
24
  # 設定輸出元件
 
3
  tokenizer = AutoTokenizer.from_pretrained("CodeTed/CGEDit")
4
  model = T5ForConditionalGeneration.from_pretrained("CodeTed/CGEDit")
5
 
 
6
  def cged_correction(sentence, function):
7
+ prompt = {"錯別字校正":"糾正句子中的錯字:", "文法校正":"糾正句子中的錯誤:",
8
+ "文本重構":"在不改動文意的情況下改寫句子:", "文本簡化":"在不改動文意的情況下改寫句子:", "整體校正":"修改句子的錯誤或使其更通順:"}
9
+ input_ids = tokenizer(prompt[function] + sentence, return_tensors="pt").input_ids
10
  outputs = model.generate(input_ids, max_length=200)
11
  edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
  return edited_text
 
14
  with gr.Blocks() as demo:
15
  gr.Markdown(
16
  """
17
+ # Chinese Grammarly - 中文文本自動編輯器
18
+ ### 貼上中文文章來使你的句子更順暢~
19
  Start typing below to see the correction.
20
  """
21
  )
22
+ funt = gr.Radio(["錯別字校正", "文法校正", "文本重構", "文本簡化", "整體校正"])
23
  #設定輸入元件
24
  sent = gr.Textbox(label="Sentence", placeholder="input the sentence")
25
  # 設定輸出元件