|
import gradio as gr |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer |
|
|
|
def formatOutput(modelOutput): |
|
|
|
logits = modelOutput.get("logits") |
|
rawScore = logits.tolist().pop().pop() |
|
return f"{rawScore:.3f}" |
|
|
|
def processInput(input): |
|
|
|
model = AutoModelForSequenceClassification.from_pretrained("garrettbaber/twitter-roberta-base-fear-intensity") |
|
tokenizer = AutoTokenizer.from_pretrained("garrettbaber/twitter-roberta-base-fear-intensity") |
|
|
|
tokens = tokenizer(input, return_tensors="pt") |
|
|
|
outputs = model(**tokens) |
|
return formatOutput(outputs) |
|
|
|
app = gr.Interface(fn=processInput, inputs="text", outputs="text") |
|
|
|
app.launch() |