Unknownaut commited on
Commit
9b167d9
·
verified ·
1 Parent(s): 873fade

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ MODEL_NAME = "Unknownaut/entity-level-framing-news-roberta"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
8
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
9
+
10
+ labels = ["Legitimate", "Aggressor", "Defensive", "Neutral"]
11
+
12
+ def predict(sentence, entity):
13
+ inputs = tokenizer(
14
+ sentence,
15
+ entity,
16
+ return_tensors="pt",
17
+ truncation=True,
18
+ max_length=160
19
+ )
20
+
21
+ with torch.inference_mode():
22
+ outputs = model(**inputs)
23
+ pred = torch.argmax(outputs.logits, dim=1).item()
24
+
25
+ return labels[pred]
26
+
27
+ demo = gr.Interface(
28
+ fn=predict,
29
+ inputs=["text", "text"],
30
+ outputs="text"
31
+ )
32
+
33
+ demo.launch()