Spaces:
Build error
Build error
File size: 752 Bytes
0b476dd 5cda48b 0b476dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from transformers import BertTokenizerFast, BertForSequenceClassification
import torch
model = BertForSequenceClassification.from_pretrained('./ch-sent-check-model')
tokenizer = BertTokenizerFast.from_pretrained('./ch-sent-check-model')
def judge(sentence):
input_ids = tokenizer(sentence,return_tensors='pt')['input_ids']
out = model(input_ids)
logits = out.logits
pred = torch.argmax(logits,dim=-1).item()
pred_text = 'Incorrect' if pred == 0 else 'Correct'
return pred_text
iface = gr.Interface(
fn=judge,
inputs=gr.Textbox(
label="請輸入一段中文句子來檢測正確性",
lines=1,
value="請注意用字的鄭確性",
),
outputs="text"
)
iface.launch() |