Spaces:
Runtime error
Runtime error
thiruvanth
commited on
Commit
•
292d488
1
Parent(s):
71411c5
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,18 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
|
|
|
|
|
|
|
6 |
MODEL_PATH = 'finiteautomata/bertweet-base-sentiment-analysis'
|
7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
8 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
9 |
model = model.to(device)
|
10 |
|
|
|
|
|
|
|
|
|
11 |
|
12 |
logits = outputs.logits
|
13 |
sigmoid = torch.nn.Sigmoid()
|
@@ -19,7 +26,6 @@ for i, k in enumerate(label2id.keys()):
|
|
19 |
|
20 |
|
21 |
label2id = {k: v for k, v in sorted(label2id.items(), key=lambda item: item[1], reverse=True)}
|
22 |
-
label2id
|
23 |
|
24 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
25 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
@@ -37,8 +43,8 @@ def get_predictions(input_text: str) -> dict:
|
|
37 |
for i, k in enumerate(label2id.keys()):
|
38 |
label2id[k] = probs[i]
|
39 |
label2id = {k: float(v) for k, v in sorted(label2id.items(), key=lambda item: item[1].item(), reverse=True)}
|
40 |
-
|
41 |
-
|
42 |
import gradio as gr
|
43 |
gr.Interface(
|
44 |
fn=get_predictions,
|
|
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
|
6 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
7 |
+
|
8 |
+
|
9 |
MODEL_PATH = 'finiteautomata/bertweet-base-sentiment-analysis'
|
10 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
11 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
12 |
model = model.to(device)
|
13 |
|
14 |
+
inputs = tokenizer(query, return_tensors='pt', truncation=True)
|
15 |
+
inputs = inputs.to(device)
|
16 |
+
outputs = model(**inputs)
|
17 |
+
label2id = model.config.label2id
|
18 |
|
19 |
logits = outputs.logits
|
20 |
sigmoid = torch.nn.Sigmoid()
|
|
|
26 |
|
27 |
|
28 |
label2id = {k: v for k, v in sorted(label2id.items(), key=lambda item: item[1], reverse=True)}
|
|
|
29 |
|
30 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
31 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
|
|
|
43 |
for i, k in enumerate(label2id.keys()):
|
44 |
label2id[k] = probs[i]
|
45 |
label2id = {k: float(v) for k, v in sorted(label2id.items(), key=lambda item: item[1].item(), reverse=True)}
|
46 |
+
return label2id
|
47 |
+
|
48 |
import gradio as gr
|
49 |
gr.Interface(
|
50 |
fn=get_predictions,
|