Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import torch.nn.functional as F
|
|
6 |
import torch.nn as nn
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
|
|
9 |
model = AutoModelForSequenceClassification.from_pretrained(model_path, num_labels=1, load_in_8bit=True)
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
@@ -13,10 +14,12 @@ tokenizer = AutoTokenizer.from_pretrained(model_path)
|
|
13 |
|
14 |
@spaces.GPU
|
15 |
def predict(title, abstract):
|
|
|
|
|
16 |
model.eval()
|
17 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
18 |
inputs = tokenizer(text, return_tensors="pt")
|
19 |
-
inputs = inputs.to(
|
20 |
with torch.no_grad():
|
21 |
outputs = model(**inputs)
|
22 |
probability = torch.sigmoid(outputs.logits).item()
|
|
|
6 |
import torch.nn as nn
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
9 |
+
|
10 |
model = AutoModelForSequenceClassification.from_pretrained(model_path, num_labels=1, load_in_8bit=True)
|
11 |
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
|
|
14 |
|
15 |
@spaces.GPU
|
16 |
def predict(title, abstract):
|
17 |
+
torch.cuda.set_device(torch.device('cuda'))
|
18 |
+
|
19 |
model.eval()
|
20 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
21 |
inputs = tokenizer(text, return_tensors="pt")
|
22 |
+
inputs = inputs.to(torch.device('cuda'))
|
23 |
with torch.no_grad():
|
24 |
outputs = model(**inputs)
|
25 |
probability = torch.sigmoid(outputs.logits).item()
|