Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -7,24 +7,20 @@ import torch.nn as nn
|
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
9 |
|
10 |
-
@spaces.GPU
|
11 |
-
def init_model():
|
12 |
-
global model, tokenizer
|
13 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
14 |
-
model_path,
|
15 |
-
num_labels=1,
|
16 |
-
load_in_8bit=True,
|
17 |
-
)
|
18 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
19 |
-
model.eval()
|
20 |
-
return model, tokenizer
|
21 |
|
22 |
-
model, tokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
@spaces.GPU
|
25 |
def predict(title, abstract):
|
26 |
-
global model, tokenizer
|
27 |
-
|
28 |
model_device = next(model.parameters()).device
|
29 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
30 |
inputs = tokenizer(text, return_tensors="pt").to(model_device)
|
|
|
7 |
import re
|
8 |
model_path = r'ssocean/NAIP'
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
global model, tokenizer
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
13 |
+
model_path,
|
14 |
+
num_labels=1,
|
15 |
+
load_in_8bit=True,
|
16 |
+
)
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
18 |
+
model.eval()
|
19 |
+
|
20 |
+
|
21 |
|
22 |
@spaces.GPU
|
23 |
def predict(title, abstract):
|
|
|
|
|
24 |
model_device = next(model.parameters()).device
|
25 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
26 |
inputs = tokenizer(text, return_tensors="pt").to(model_device)
|