garrettbaber's picture
uses joy intensity model
689c437
raw
history blame contribute delete
761 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-joy-intensity")
tokenizer = AutoTokenizer.from_pretrained("garrettbaber/twitter-roberta-base-joy-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()