Jackss
commited on
Commit
·
c4c2d5a
1
Parent(s):
3c07819
Stuff
Browse files
main.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi.responses import FileResponse
|
|
4 |
from transformers import AutoTokenizer, AutoModel
|
5 |
import numpy as np
|
6 |
from sklearn.metrics.pairwise import cosine_similarity
|
|
|
7 |
|
8 |
# load model and tokenizer
|
9 |
tokenizer = AutoTokenizer.from_pretrained('allenai/specter')
|
@@ -15,13 +16,17 @@ model = AutoModel.from_pretrained('allenai/specter')
|
|
15 |
# concatenate title and abstract
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
18 |
app = FastAPI()
|
19 |
|
20 |
|
21 |
|
22 |
@app.post('/similarity')
|
23 |
-
def similarity(input):
|
24 |
-
papers = input
|
25 |
title_abs = [d['title'] + tokenizer.sep_token + (d.get('abstract') or '') for d in papers]
|
26 |
# preprocess the input
|
27 |
inputs = tokenizer(title_abs, padding=True, truncation=True, return_tensors="pt", max_length=512)
|
|
|
4 |
from transformers import AutoTokenizer, AutoModel
|
5 |
import numpy as np
|
6 |
from sklearn.metrics.pairwise import cosine_similarity
|
7 |
+
from pydantic import BaseModel
|
8 |
|
9 |
# load model and tokenizer
|
10 |
tokenizer = AutoTokenizer.from_pretrained('allenai/specter')
|
|
|
16 |
# concatenate title and abstract
|
17 |
|
18 |
|
19 |
+
class Input(BaseModel):
|
20 |
+
papers: list = []
|
21 |
+
|
22 |
+
|
23 |
app = FastAPI()
|
24 |
|
25 |
|
26 |
|
27 |
@app.post('/similarity')
|
28 |
+
def similarity(input: Input):
|
29 |
+
papers = input.papers
|
30 |
title_abs = [d['title'] + tokenizer.sep_token + (d.get('abstract') or '') for d in papers]
|
31 |
# preprocess the input
|
32 |
inputs = tokenizer(title_abs, padding=True, truncation=True, return_tensors="pt", max_length=512)
|