Spaces:
Running
Running
shibing624
commited on
Commit
·
c659f9c
1
Parent(s):
d8e4e79
update init app.
Browse files
app.py
CHANGED
|
@@ -3,15 +3,13 @@ import operator
|
|
| 3 |
import torch
|
| 4 |
from transformers import BertTokenizer, BertForMaskedLM
|
| 5 |
|
| 6 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 7 |
tokenizer = BertTokenizer.from_pretrained("shibing624/macbert4csc-base-chinese")
|
| 8 |
model = BertForMaskedLM.from_pretrained("shibing624/macbert4csc-base-chinese")
|
| 9 |
-
model.to(device)
|
| 10 |
|
| 11 |
|
| 12 |
def ai_text(texts):
|
| 13 |
with torch.no_grad():
|
| 14 |
-
outputs = model(**tokenizer(texts, padding=True, return_tensors='pt')
|
| 15 |
|
| 16 |
def get_errors(corrected_text, origin_text):
|
| 17 |
sub_details = []
|
|
@@ -42,12 +40,14 @@ def ai_text(texts):
|
|
| 42 |
return result
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
| 45 |
examples = [
|
| 46 |
['真麻烦你了。希望你们好好的跳无'],
|
| 47 |
['少先队员因该为老人让坐'],
|
| 48 |
['机七学习是人工智能领遇最能体现智能的一个分知'],
|
| 49 |
-
['今天心情很好',
|
| 50 |
-
|
| 51 |
['遇到一位很棒的奴生跟我聊天。'],
|
| 52 |
['他的语说的很好,法语也不错'],
|
| 53 |
['他法语说的很好,的语也不错'],
|
|
@@ -56,6 +56,6 @@ examples = [
|
|
| 56 |
]
|
| 57 |
|
| 58 |
output_text = gr.outputs.Textbox()
|
| 59 |
-
gr.Interface(ai_text, "
|
| 60 |
description="Copy or input error Chinese text. Submit and the machine will correct text.",
|
| 61 |
examples=examples).launch()
|
|
|
|
| 3 |
import torch
|
| 4 |
from transformers import BertTokenizer, BertForMaskedLM
|
| 5 |
|
|
|
|
| 6 |
tokenizer = BertTokenizer.from_pretrained("shibing624/macbert4csc-base-chinese")
|
| 7 |
model = BertForMaskedLM.from_pretrained("shibing624/macbert4csc-base-chinese")
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def ai_text(texts):
|
| 11 |
with torch.no_grad():
|
| 12 |
+
outputs = model(**tokenizer(texts, padding=True, return_tensors='pt'))
|
| 13 |
|
| 14 |
def get_errors(corrected_text, origin_text):
|
| 15 |
sub_details = []
|
|
|
|
| 40 |
return result
|
| 41 |
|
| 42 |
|
| 43 |
+
print(ai_text(['少先队员因该为老人让坐']))
|
| 44 |
+
|
| 45 |
examples = [
|
| 46 |
['真麻烦你了。希望你们好好的跳无'],
|
| 47 |
['少先队员因该为老人让坐'],
|
| 48 |
['机七学习是人工智能领遇最能体现智能的一个分知'],
|
| 49 |
+
['今天心情很好'],
|
| 50 |
+
['老是较书。'],
|
| 51 |
['遇到一位很棒的奴生跟我聊天。'],
|
| 52 |
['他的语说的很好,法语也不错'],
|
| 53 |
['他法语说的很好,的语也不错'],
|
|
|
|
| 56 |
]
|
| 57 |
|
| 58 |
output_text = gr.outputs.Textbox()
|
| 59 |
+
gr.Interface(ai_text, "text", "text", title="Chinese Text Correction shibing624/macbert4csc-base-chinese",
|
| 60 |
description="Copy or input error Chinese text. Submit and the machine will correct text.",
|
| 61 |
examples=examples).launch()
|