Spaces:
Runtime error
Runtime error
File size: 946 Bytes
568da45 |
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 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import torch
import os
import transformers
from transformers import (
AutoModelForSequenceClassification,
AutoTokenizer,
)
from deployment import preprocess, detect
device = 'cpu'
model_dir = "nealcly/detection-longformer"
# load the Longformer detector
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoModelForSequenceClassification.from_pretrained(model_dir).to(device)
def detect(input_text,device,th=-3.08583984375):
label2decisions = {
0: "machine-generated",
1: "human-written",
}
tokenize_input = tokenizer(input_text)
tensor_input = torch.tensor([tokenize_input["input_ids"]]).to(device)
outputs = model(tensor_input)
is_machine = -outputs.logits[0][0].item()
if is_machine < th:
decision = 0
else:
decision = 1
return label2decisions[decision]
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch() |