saideep-arikontham commited on
Commit
3b1b881
1 Parent(s): ca3816a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoModel, AutoTokenizer
3
+ import torch
4
+
5
+ model_checkpoint = 'saideep-arikontham/twitter-roberta-base-sentiment-latest-trump-stance'
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, num_labels=2, ignore_mismatched_sizes=True)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
8
+
9
+ def greet(text):
10
+
11
+ model.to('mps')
12
+ inputs = tokenizer.encode(text, return_tensors="pt").to("mps")
13
+ # compute logits
14
+ logits = model(inputs).logits
15
+ # convert logits to label
16
+ predictions = torch.argmax(logits)
17
+
18
+ return "This text is " + id2label[predictions.tolist()] + "!!"
19
+
20
+
21
+
22
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
23
+ demo.launch()