Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -165,7 +165,7 @@ def search(query: str, k: int = 5):
|
|
| 165 |
type: object
|
| 166 |
properties:
|
| 167 |
query: {type: string, description: "User query in natural language."}
|
| 168 |
-
k: {type: integer, minimum: 1, maximum:
|
| 169 |
required: ["query"]
|
| 170 |
|
| 171 |
Args:
|
|
@@ -196,11 +196,21 @@ def search(query: str, k: int = 5):
|
|
| 196 |
scores = processor.score(qs, ds, device=device)
|
| 197 |
top_k_indices = scores[0].topk(k).indices.tolist()
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# Build gallery results with 1-based page numbering
|
| 202 |
results = []
|
| 203 |
-
for idx in
|
| 204 |
page_num = idx + 1
|
| 205 |
results.append((images[idx], f"Page {page_num}"))
|
| 206 |
|
|
@@ -264,7 +274,7 @@ ColPali is implemented from the [ColPali paper](https://arxiv.org/abs/2407.01449
|
|
| 264 |
with gr.Column(scale=3):
|
| 265 |
gr.Markdown("## 2️⃣ Search")
|
| 266 |
query = gr.Textbox(placeholder="Enter your query here", label="Query")
|
| 267 |
-
k_slider = gr.Slider(minimum=1, maximum=
|
| 268 |
search_button = gr.Button("🔍 Search", variant="primary")
|
| 269 |
output_text = gr.Textbox(label="AI Response", placeholder="Generated response based on retrieved documents")
|
| 270 |
|
|
|
|
| 165 |
type: object
|
| 166 |
properties:
|
| 167 |
query: {type: string, description: "User query in natural language."}
|
| 168 |
+
k: {type: integer, minimum: 1, maximum: 10, default: 5. description: "Number of top pages to retrieve."}
|
| 169 |
required: ["query"]
|
| 170 |
|
| 171 |
Args:
|
|
|
|
| 196 |
scores = processor.score(qs, ds, device=device)
|
| 197 |
top_k_indices = scores[0].topk(k).indices.tolist()
|
| 198 |
|
| 199 |
+
# Base set & neighbor expansion
|
| 200 |
+
base = set(top_k_indices)
|
| 201 |
+
expanded = set(base)
|
| 202 |
+
for i in base:
|
| 203 |
+
expanded.add(i - 1)
|
| 204 |
+
expanded.add(i + 1)
|
| 205 |
+
|
| 206 |
+
expanded = {i for i in expanded if i >= 0 and i<=len(images)}
|
| 207 |
+
|
| 208 |
+
expanded_indices = sorted(expanded)
|
| 209 |
+
print(top_k_indices, expanded_indices)
|
| 210 |
|
| 211 |
# Build gallery results with 1-based page numbering
|
| 212 |
results = []
|
| 213 |
+
for idx in expanded_indices:
|
| 214 |
page_num = idx + 1
|
| 215 |
results.append((images[idx], f"Page {page_num}"))
|
| 216 |
|
|
|
|
| 274 |
with gr.Column(scale=3):
|
| 275 |
gr.Markdown("## 2️⃣ Search")
|
| 276 |
query = gr.Textbox(placeholder="Enter your query here", label="Query")
|
| 277 |
+
k_slider = gr.Slider(minimum=1, maximum=10, step=1, label="Number of results", value=5)
|
| 278 |
search_button = gr.Button("🔍 Search", variant="primary")
|
| 279 |
output_text = gr.Textbox(label="AI Response", placeholder="Generated response based on retrieved documents")
|
| 280 |
|