change backend
Browse files- app.py +21 -5
- requirements.txt +2 -1
app.py
CHANGED
@@ -10,14 +10,29 @@ from fasthtml.common import * # noqa
|
|
10 |
from huggingface_hub import login, whoami
|
11 |
from rerankers import Reranker
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def get_images(query: str):
|
15 |
-
url = "http://
|
16 |
|
17 |
response = requests.get(url, params={"query": query})
|
18 |
return response.json()
|
19 |
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
dotenv.load_dotenv()
|
22 |
login(token=os.environ.get("HF_TOKEN"))
|
23 |
|
@@ -101,11 +116,12 @@ def retrieve_and_rerank(query, k=3):
|
|
101 |
|
102 |
# re-rank
|
103 |
docs = [f"{item['title']} {item['abstract']}" for item in retrieved]
|
104 |
-
results = ranker.rank(query=query, docs=docs)
|
|
|
105 |
|
106 |
-
ranked_doc_ids = []
|
107 |
-
for result in results[:k]:
|
108 |
-
|
109 |
|
110 |
final_results = [retrieved[idx] for idx in ranked_doc_ids]
|
111 |
final_results = _format_results(final_results)
|
|
|
10 |
from huggingface_hub import login, whoami
|
11 |
from rerankers import Reranker
|
12 |
|
13 |
+
# def get_images(query: str):
|
14 |
+
# url = "http://147.189.194.113:80/get_pages"
|
15 |
+
|
16 |
+
# response = requests.get(url, params={"query": query})
|
17 |
+
# return response.json()
|
18 |
+
|
19 |
|
20 |
def get_images(query: str):
|
21 |
+
url = "http://47.47.180.31:80/get_pages"
|
22 |
|
23 |
response = requests.get(url, params={"query": query})
|
24 |
return response.json()
|
25 |
|
26 |
|
27 |
+
def rerank_api(query, docs):
|
28 |
+
url = "http://47.47.180.31:80/rerank"
|
29 |
+
|
30 |
+
params = {"query": query, "docs": docs}
|
31 |
+
|
32 |
+
response = requests.get(url, params=params)
|
33 |
+
return response.json()
|
34 |
+
|
35 |
+
|
36 |
dotenv.load_dotenv()
|
37 |
login(token=os.environ.get("HF_TOKEN"))
|
38 |
|
|
|
116 |
|
117 |
# re-rank
|
118 |
docs = [f"{item['title']} {item['abstract']}" for item in retrieved]
|
119 |
+
# results = ranker.rank(query=query, docs=docs)
|
120 |
+
ranked_doc_ids = rerank_api(query, docs)["ranked_doc_ids"][:k]
|
121 |
|
122 |
+
# ranked_doc_ids = []
|
123 |
+
# for result in results[:k]:
|
124 |
+
# ranked_doc_ids.append(result.doc_id)
|
125 |
|
126 |
final_results = [retrieved[idx] for idx in ranked_doc_ids]
|
127 |
final_results = _format_results(final_results)
|
requirements.txt
CHANGED
@@ -13,4 +13,5 @@ tantivy==0.22.0
|
|
13 |
lancedb
|
14 |
rerankers==0.5.3
|
15 |
transformers
|
16 |
-
torch
|
|
|
|
13 |
lancedb
|
14 |
rerankers==0.5.3
|
15 |
transformers
|
16 |
+
torch
|
17 |
+
pillow
|