Pranjal12345 commited on
Commit
8abc006
·
1 Parent(s): 78d7995

app file added

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
5
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
6
+
7
+ import gradio as gr
8
+
9
+ def greet(my_text):
10
+ with torch.no_grad():
11
+ tokens = tokenizer(my_text, padding=True, truncation=True, return_tensors="pt")
12
+ outputs = model(**tokens)
13
+ logits = outputs.logits
14
+ probabilities = torch.softmax(logits, dim=1)
15
+ label_ids = torch.argmax(probabilities, dim=1)
16
+ labels = ['Negative', 'Positive']
17
+ label = labels[label_ids]
18
+ return label
19
+
20
+
21
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text", title="Sentiment Analysis",description ="Classify a text into either Positive or negative",
22
+ article = "hey my nam is pranjal khadka")
23
+
24
+ demo.launch(share = True)