File size: 476 Bytes
38d4932
 
 
 
 
 
 
 
 
50c2eab
38d4932
 
 
b2830ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import pipeline, LongformerForSequenceClassification, LongformerTokenizer, Trainer
import gradio as gr


def predict_fn(text: str) -> str:
    model = LongformerForSequenceClassification.from_pretrained("model")
    tokenizer = LongformerTokenizer.from_pretrained("allenai/longformer-base-4096")

    p = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
    return p(text)[0]["label"]


gr.Interface(predict_fn, "textbox", "label").launch()