File size: 766 Bytes
3b1b881 2f7bc0e 3b1b881 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoModel, AutoTokenizer
import torch
base_model = "cardiffnlp/twitter-roberta-base-sentiment-latest"
adapter_model = 'saideep-arikontham/twitter-roberta-base-sentiment-latest-trump-stance'
model = PeftModel.from_pretrained(model, adapter_model)
tokenizer = AutoTokenizer.from_pretrained(adapter_model)
def greet(text):
model.to('mps')
inputs = tokenizer.encode(text, return_tensors="pt").to("mps")
# compute logits
logits = model(inputs).logits
# convert logits to label
predictions = torch.argmax(logits)
return "This text is " + id2label[predictions.tolist()] + "!!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch() |