Spaces:
Sleeping
Sleeping
jonathanjordan21
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@app.get("/")
|
6 |
def greet_json():
|
7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
import numpy as np
|
3 |
+
from sentence_transformers import CrossEncoder
|
4 |
+
from typing import List
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
+
class InputModel(BaseModel):
|
9 |
+
keywords: List[str]
|
10 |
+
contents: List[str]
|
11 |
+
|
12 |
+
model = CrossEncoder(
|
13 |
+
"jinaai/jina-reranker-v2-base-multilingual",
|
14 |
+
trust_remote_code=True,
|
15 |
+
)
|
16 |
+
|
17 |
@app.get("/")
|
18 |
def greet_json():
|
19 |
return {"Hello": "World!"}
|
20 |
+
|
21 |
+
@app.post("/predict")
|
22 |
+
def predict(inp : InputModel):
|
23 |
+
sentence_pairs = [[query, doc] for query,doc in zip(inp.keywords, inp.contents)]
|
24 |
+
scores = model.predict(sentence_pairs, convert_to_tensor=False)#.tolist()
|
25 |
+
# (-scores).argsort().tolist()
|
26 |
+
return {"results":scores.tolist()}
|
27 |
+
|
28 |
+
# keywords = model.encode(inp.keywords)
|
29 |
+
# contents = model.encode(inp.contents)
|
30 |
+
# return {"results":np.linalg.norm(contents-keywords).tolist()}
|
31 |
+
|