garrettbaber's picture
fix param name
9be3e5a
raw
history blame contribute delete
763 Bytes
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-fear-intensity")
tokenizer = AutoTokenizer.from_pretrained("garrettbaber/twitter-roberta-base-fear-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()