sam2ai commited on
Commit
5382507
·
1 Parent(s): c61b22c

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -80,6 +80,13 @@ app = FastAPI(title="embedding Inference")
80
  # templates = Jinja2Templates(directory="templates")
81
  # model_semaphore = None
82
 
 
 
 
 
 
 
 
83
 
84
  @app.post("/embed")
85
  async def api_embed(
@@ -87,10 +94,7 @@ async def api_embed(
87
  text2: str = Body("text2", description="", embed=True),
88
  ):
89
 
90
- q_embeddings = model.encode(text1, normalize_embeddings=True)
91
- p_embeddings = model.encode(text2, normalize_embeddings=True)
92
-
93
- scores = q_embeddings @ p_embeddings.T
94
  print(scores)
95
  scores = scores.tolist()
96
 
 
80
  # templates = Jinja2Templates(directory="templates")
81
  # model_semaphore = None
82
 
83
+ def similarity_score(textA, textB):
84
+ em_test = model.encode(
85
+ [textA, textB],
86
+ normalize_embeddings=True
87
+ )
88
+ return em_test[0] @ em_test[1].T
89
+
90
 
91
  @app.post("/embed")
92
  async def api_embed(
 
94
  text2: str = Body("text2", description="", embed=True),
95
  ):
96
 
97
+ scores = similarity_score(text1, text2)
 
 
 
98
  print(scores)
99
  scores = scores.tolist()
100