Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,24 +9,19 @@ model_path = r'ssocean/NAIP'
|
|
9 |
device = 'cuda:0'
|
10 |
|
11 |
global model, tokenizer
|
12 |
-
model =
|
13 |
-
|
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(duration=60, enable_queue=True)
|
23 |
def predict(title, abstract):
|
24 |
-
model
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
)
|
|
|
30 |
text = f'''Given a certain paper, Title: {title}\n Abstract: {abstract}. \n Predict its normalized academic impact (between 0 and 1):'''
|
31 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
32 |
with torch.no_grad():
|
|
|
9 |
device = 'cuda:0'
|
10 |
|
11 |
global model, tokenizer
|
12 |
+
model = None
|
13 |
+
tokenizer = None
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
@spaces.GPU(duration=60, enable_queue=True)
|
17 |
def predict(title, abstract):
|
18 |
+
if model is None:
|
19 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
20 |
+
model_path,
|
21 |
+
num_labels=1,
|
22 |
+
load_in_8bit=True,)
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
24 |
+
model.eval()
|
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(device)
|
27 |
with torch.no_grad():
|