Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,19 +10,15 @@ model = AutoModelForSequenceClassification.from_pretrained(model_path, num_label
|
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
12 |
|
13 |
-
device = "cuda"
|
14 |
-
|
15 |
-
model.eval()
|
16 |
|
17 |
@spaces.GPU
|
18 |
def predict(title, abstract):
|
19 |
-
model.
|
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 |
with torch.no_grad():
|
23 |
-
outputs = model(**inputs
|
24 |
-
print("Model device:", next(model.parameters()).device)
|
25 |
-
print("Inputs device:", inputs.device)
|
26 |
probability = torch.sigmoid(outputs.logits).item()
|
27 |
# reason for +0.05: We observed that the predicted values in the web demo are generally around 0.05 lower than those in the local deployment (due to differences in software/hardware environments). Therefore, we applied the following compensation in the web demo. Please do not use this in the local deployment.
|
28 |
if probability + 0.05 >=1.0:
|
|
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
12 |
|
|
|
|
|
|
|
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("cuda")
|
20 |
with torch.no_grad():
|
21 |
+
outputs = model(**inputs)
|
|
|
|
|
22 |
probability = torch.sigmoid(outputs.logits).item()
|
23 |
# reason for +0.05: We observed that the predicted values in the web demo are generally around 0.05 lower than those in the local deployment (due to differences in software/hardware environments). Therefore, we applied the following compensation in the web demo. Please do not use this in the local deployment.
|
24 |
if probability + 0.05 >=1.0:
|