Spaces:
Sleeping
Sleeping
File size: 966 Bytes
8abc006 6ec2341 8abc006 1807a06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
import gradio as gr
def greet(my_text):
with torch.no_grad():
tokens = tokenizer(my_text, padding=True, truncation=True, return_tensors="pt")
outputs = model(**tokens)
logits = outputs.logits
probabilities = torch.softmax(logits, dim=1)
label_ids = torch.argmax(probabilities, dim=1)
labels = ['Negative', 'Positive']
label = labels[label_ids]
return label
demo = gr.Interface(fn=greet, inputs="text", outputs="text", title="Sentiment Analysis",description ="Classify a text into either Positive or negative",
article = "hey my name is pranjal khadka and this is a sentiment analysis app")
demo.launch() |