HUANG-Stephanie commited on
Commit
285d8ef
1 Parent(s): a139f0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -78,11 +78,16 @@ async def search(query: str, k: int):
78
  embeddings_query = model(**batch_query)
79
  qs.extend(list(torch.unbind(embeddings_query.to("cpu"))))
80
 
81
- # run evaluation
82
  retriever_evaluator = CustomEvaluator(is_multi_vector=True)
83
  scores = retriever_evaluator.evaluate(qs, ds)
84
- best_page = int(scores.argmax(axis=1).item())
85
- return f"The most relevant page is {best_page}", images[best_page]
 
 
 
 
 
 
86
 
87
  if __name__ == "__main__":
88
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
78
  embeddings_query = model(**batch_query)
79
  qs.extend(list(torch.unbind(embeddings_query.to("cpu"))))
80
 
 
81
  retriever_evaluator = CustomEvaluator(is_multi_vector=True)
82
  scores = retriever_evaluator.evaluate(qs, ds)
83
+
84
+ top_k_indices = scores.argsort(axis=1)[0][-k:][::-1]
85
+
86
+ results = []
87
+ for idx in top_k_indices:
88
+ results.append({"image": str(images[idx]), "page": f"Page {idx}"})
89
+
90
+ return {"results": results}
91
 
92
  if __name__ == "__main__":
93
  uvicorn.run(app, host="0.0.0.0", port=7860)