File size: 769 Bytes
17831ec 38d7836 17831ec 2925dbb 9be3e5a 2925dbb 8ee74ad 416a17c 83bc317 416a17c 8ee74ad 416a17c 35902f0 2925dbb 38d7836 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer
def formatOutput(modelOutput):
#parse output
logits = modelOutput.get("logits")
rawScore = logits.tolist().pop().pop()
return f"{rawScore:.3f}"
def processInput(input):
#load model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("garrettbaber/twitter-roberta-base-sadness-intensity")
tokenizer = AutoTokenizer.from_pretrained("garrettbaber/twitter-roberta-base-sadness-intensity")
#get tokens
tokens = tokenizer(input, return_tensors="pt")
#pass tokens to model
outputs = model(**tokens)
return formatOutput(outputs)
app = gr.Interface(fn=processInput, inputs="text", outputs="text")
app.launch() |