Spaces:
Sleeping
Sleeping
| 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() |