saideep-arikontham
commited on
Commit
•
4277173
1
Parent(s):
60b09de
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForSequenceClassification,
|
3 |
import torch
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
|
6 |
base_model = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
7 |
adapter_model = 'saideep-arikontham/twitter-roberta-base-sentiment-latest-trump-stance'
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
model = PeftModel.from_pretrained(model, adapter_model)
|
10 |
tokenizer = AutoTokenizer.from_pretrained(adapter_model)
|
11 |
|
12 |
-
|
13 |
def greet(text):
|
14 |
|
15 |
model.to('mps')
|
@@ -22,5 +28,6 @@ def greet(text):
|
|
22 |
return "This text is " + id2label[predictions.tolist()] + "!!"
|
23 |
|
24 |
|
|
|
25 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
26 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
import torch
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
|
6 |
base_model = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
7 |
adapter_model = 'saideep-arikontham/twitter-roberta-base-sentiment-latest-trump-stance'
|
8 |
|
9 |
+
# define label maps
|
10 |
+
id2label = {0: "Anti-Trump", 1 : "Pro-Trump"}
|
11 |
+
label2id = {"Anti-Trump" : 0, "Pro-Trump" : 1}
|
12 |
+
|
13 |
+
# generate classification model from model_checkpoint
|
14 |
+
model = AutoModelForSequenceClassification.from_pretrained(base_model, num_labels=2, id2label = id2label, label2id = label2id, ignore_mismatched_sizes=True)
|
15 |
+
|
16 |
model = PeftModel.from_pretrained(model, adapter_model)
|
17 |
tokenizer = AutoTokenizer.from_pretrained(adapter_model)
|
18 |
|
|
|
19 |
def greet(text):
|
20 |
|
21 |
model.to('mps')
|
|
|
28 |
return "This text is " + id2label[predictions.tolist()] + "!!"
|
29 |
|
30 |
|
31 |
+
|
32 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
33 |
demo.launch()
|