ssocean commited on
Commit
b7157af
·
verified ·
1 Parent(s): 02e9d84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -9,24 +9,19 @@ model_path = r'ssocean/NAIP'
9
  device = 'cuda:0'
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(duration=60, enable_queue=True)
23
  def predict(title, abstract):
24
- model = AutoModelForSequenceClassification.from_pretrained(
25
- model_path,
26
- num_labels=1,
27
- load_in_8bit=True,
28
- device_map={'': device(type='cuda', index=0)}
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():