TedYeh commited on
Commit
ea268c4
1 Parent(s): 7b99548

update app and requirements

Browse files
Files changed (2) hide show
  1. app.py +27 -4
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,7 +1,30 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ 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
12
+
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
+ # 設定輸出元件
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, funt], outputs=output)
30
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ sentencepiece
3
+ transformers