Spaces:
Running
on
L4
Running
on
L4
Upload folder using huggingface_hub
Browse files- frontend/app.py +18 -16
- main.py +3 -7
- output.css +4 -0
frontend/app.py
CHANGED
|
@@ -4,7 +4,7 @@ from urllib.parse import quote_plus
|
|
| 4 |
from fasthtml.components import H1, H2, Div, Form, Img, NotStr, P, Span
|
| 5 |
from fasthtml.xtend import A, Script
|
| 6 |
from lucide_fasthtml import Lucide
|
| 7 |
-
from shad4fast import Badge, Button, Input, Label, RadioGroup, RadioGroupItem
|
| 8 |
|
| 9 |
# JavaScript to check the input value and enable/disable the search button and radio buttons
|
| 10 |
check_input_script = Script(
|
|
@@ -136,17 +136,17 @@ def SearchBox(with_border=False, query_value="", ranking_value="nn+colpali"):
|
|
| 136 |
RadioGroup(
|
| 137 |
Div(
|
| 138 |
RadioGroupItem(value="nn+colpali", id="nn+colpali"),
|
| 139 |
-
Label("
|
| 140 |
cls="flex items-center space-x-2",
|
| 141 |
),
|
| 142 |
Div(
|
| 143 |
-
RadioGroupItem(value="bm25
|
| 144 |
-
Label("
|
| 145 |
cls="flex items-center space-x-2",
|
| 146 |
),
|
| 147 |
Div(
|
| 148 |
-
RadioGroupItem(value="bm25", id="bm25"),
|
| 149 |
-
Label("
|
| 150 |
cls="flex items-center space-x-2",
|
| 151 |
),
|
| 152 |
name="ranking",
|
|
@@ -276,7 +276,7 @@ def LoadingSkeleton():
|
|
| 276 |
|
| 277 |
def SimMapButtonReady(query_id, idx, token, img_src):
|
| 278 |
return Button(
|
| 279 |
-
token,
|
| 280 |
size="sm",
|
| 281 |
data_image_src=img_src,
|
| 282 |
id=f"sim-map-button-{query_id}-{idx}-{token}",
|
|
@@ -367,14 +367,20 @@ def SearchResult(results: list, query_id: Optional[str] = None):
|
|
| 367 |
Div(
|
| 368 |
Lucide(icon="file-text"),
|
| 369 |
H2(fields["title"], cls="text-xl md:text-2xl font-semibold"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
cls="flex items-center gap-2",
|
| 371 |
),
|
| 372 |
Div(
|
| 373 |
Button(
|
| 374 |
-
"
|
| 375 |
size="sm",
|
| 376 |
id=f"toggle-button-{idx}",
|
| 377 |
onclick=f"toggleTextContent({idx})",
|
|
|
|
| 378 |
),
|
| 379 |
),
|
| 380 |
cls="flex flex-wrap items-center justify-between bg-background px-3 py-4",
|
|
@@ -417,11 +423,7 @@ def SearchResult(results: list, query_id: Optional[str] = None):
|
|
| 417 |
"Page " + str(fields["page_number"]),
|
| 418 |
cls="text-foreground font-mono bold text-sm",
|
| 419 |
),
|
| 420 |
-
|
| 421 |
-
f"Relevance score: {result['relevance']:.4f}",
|
| 422 |
-
cls="flex gap-1.5 items-center justify-center",
|
| 423 |
-
),
|
| 424 |
-
cls="flex items-center justify-between",
|
| 425 |
),
|
| 426 |
Div(
|
| 427 |
Div(
|
|
@@ -441,10 +443,10 @@ def SearchResult(results: list, query_id: Optional[str] = None):
|
|
| 441 |
cls="grid bg-border p-2",
|
| 442 |
),
|
| 443 |
id=f"text-column-{idx}",
|
| 444 |
-
cls="text-column relative bg-background px-3 py-5 hidden",
|
| 445 |
),
|
| 446 |
id=f"image-text-columns-{idx}",
|
| 447 |
-
cls="relative grid grid-cols-1 border-t",
|
| 448 |
),
|
| 449 |
cls="grid grid-cols-1 grid-rows-[auto_1fr]",
|
| 450 |
),
|
|
@@ -461,7 +463,7 @@ def SearchResult(results: list, query_id: Optional[str] = None):
|
|
| 461 |
|
| 462 |
def ChatResult(query_id: str, query: str):
|
| 463 |
return Div(
|
| 464 |
-
Div("
|
| 465 |
Div(
|
| 466 |
Div(
|
| 467 |
Div(
|
|
|
|
| 4 |
from fasthtml.components import H1, H2, Div, Form, Img, NotStr, P, Span
|
| 5 |
from fasthtml.xtend import A, Script
|
| 6 |
from lucide_fasthtml import Lucide
|
| 7 |
+
from shad4fast import Badge, Button, Input, Label, RadioGroup, RadioGroupItem, Separator
|
| 8 |
|
| 9 |
# JavaScript to check the input value and enable/disable the search button and radio buttons
|
| 10 |
check_input_script = Script(
|
|
|
|
| 136 |
RadioGroup(
|
| 137 |
Div(
|
| 138 |
RadioGroupItem(value="nn+colpali", id="nn+colpali"),
|
| 139 |
+
Label("ColPali", htmlFor="ColPali"),
|
| 140 |
cls="flex items-center space-x-2",
|
| 141 |
),
|
| 142 |
Div(
|
| 143 |
+
RadioGroupItem(value="bm25", id="bm25"),
|
| 144 |
+
Label("BM25", htmlFor="BM25"),
|
| 145 |
cls="flex items-center space-x-2",
|
| 146 |
),
|
| 147 |
Div(
|
| 148 |
+
RadioGroupItem(value="bm25+colpali", id="bm25+colpali"),
|
| 149 |
+
Label("Hybrid ColPali + BM25", htmlFor="Hybrid ColPali + BM25"),
|
| 150 |
cls="flex items-center space-x-2",
|
| 151 |
),
|
| 152 |
name="ranking",
|
|
|
|
| 276 |
|
| 277 |
def SimMapButtonReady(query_id, idx, token, img_src):
|
| 278 |
return Button(
|
| 279 |
+
token.replace("\u2581", ""),
|
| 280 |
size="sm",
|
| 281 |
data_image_src=img_src,
|
| 282 |
id=f"sim-map-button-{query_id}-{idx}-{token}",
|
|
|
|
| 367 |
Div(
|
| 368 |
Lucide(icon="file-text"),
|
| 369 |
H2(fields["title"], cls="text-xl md:text-2xl font-semibold"),
|
| 370 |
+
Separator(orientation="vertical"),
|
| 371 |
+
Badge(
|
| 372 |
+
f"Relevance score: {result['relevance']:.4f}",
|
| 373 |
+
cls="flex gap-1.5 items-center justify-center",
|
| 374 |
+
),
|
| 375 |
cls="flex items-center gap-2",
|
| 376 |
),
|
| 377 |
Div(
|
| 378 |
Button(
|
| 379 |
+
"Hide Text",
|
| 380 |
size="sm",
|
| 381 |
id=f"toggle-button-{idx}",
|
| 382 |
onclick=f"toggleTextContent({idx})",
|
| 383 |
+
cls="hidden md:block",
|
| 384 |
),
|
| 385 |
),
|
| 386 |
cls="flex flex-wrap items-center justify-between bg-background px-3 py-4",
|
|
|
|
| 423 |
"Page " + str(fields["page_number"]),
|
| 424 |
cls="text-foreground font-mono bold text-sm",
|
| 425 |
),
|
| 426 |
+
cls="flex items-center justify-end",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
),
|
| 428 |
Div(
|
| 429 |
Div(
|
|
|
|
| 443 |
cls="grid bg-border p-2",
|
| 444 |
),
|
| 445 |
id=f"text-column-{idx}",
|
| 446 |
+
cls="text-column relative bg-background px-3 py-5 hidden md-grid-text-column",
|
| 447 |
),
|
| 448 |
id=f"image-text-columns-{idx}",
|
| 449 |
+
cls="relative grid grid-cols-1 border-t grid-image-text-columns",
|
| 450 |
),
|
| 451 |
cls="grid grid-cols-1 grid-rows-[auto_1fr]",
|
| 452 |
),
|
|
|
|
| 463 |
|
| 464 |
def ChatResult(query_id: str, query: str):
|
| 465 |
return Div(
|
| 466 |
+
Div("AI-generated response", cls="text-xl font-semibold p-3"),
|
| 467 |
Div(
|
| 468 |
Div(
|
| 469 |
Div(
|
main.py
CHANGED
|
@@ -95,7 +95,7 @@ gemini_model = genai.GenerativeModel(
|
|
| 95 |
)
|
| 96 |
STATIC_DIR = Path(__file__).parent / "static"
|
| 97 |
IMG_DIR = STATIC_DIR / "saved"
|
| 98 |
-
os.makedirs(
|
| 99 |
|
| 100 |
|
| 101 |
@app.on_event("startup")
|
|
@@ -307,14 +307,10 @@ async def full_image(docid: str, query_id: str, idx: int):
|
|
| 307 |
Endpoint to get the full quality image for a given result id.
|
| 308 |
"""
|
| 309 |
image_data = await vespa_app.get_full_image_from_vespa(docid)
|
| 310 |
-
# Update the cache with the full image data
|
| 311 |
asyncio.create_task(update_full_image_cache(docid, query_id, idx, image_data))
|
| 312 |
-
# Save the image to a file
|
| 313 |
-
img_path = IMG_DIR / f"{docid}.jpg"
|
| 314 |
-
with open(img_path, "wb") as f:
|
| 315 |
-
f.write(base64.b64decode(image_data))
|
| 316 |
return Img(
|
| 317 |
-
src=f"/
|
| 318 |
alt="something",
|
| 319 |
cls="result-image w-full h-full object-contain",
|
| 320 |
)
|
|
|
|
| 95 |
)
|
| 96 |
STATIC_DIR = Path(__file__).parent / "static"
|
| 97 |
IMG_DIR = STATIC_DIR / "saved"
|
| 98 |
+
os.makedirs(STATIC_DIR, exist_ok=True)
|
| 99 |
|
| 100 |
|
| 101 |
@app.on_event("startup")
|
|
|
|
| 307 |
Endpoint to get the full quality image for a given result id.
|
| 308 |
"""
|
| 309 |
image_data = await vespa_app.get_full_image_from_vespa(docid)
|
| 310 |
+
# Update the cache with the full image data
|
| 311 |
asyncio.create_task(update_full_image_cache(docid, query_id, idx, image_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
return Img(
|
| 313 |
+
src=f"data:image/png;base64,{image_data}",
|
| 314 |
alt="something",
|
| 315 |
cls="result-image w-full h-full object-contain",
|
| 316 |
)
|
output.css
CHANGED
|
@@ -1142,6 +1142,10 @@ body {
|
|
| 1142 |
align-items: center;
|
| 1143 |
}
|
| 1144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1145 |
.justify-center {
|
| 1146 |
justify-content: center;
|
| 1147 |
}
|
|
|
|
| 1142 |
align-items: center;
|
| 1143 |
}
|
| 1144 |
|
| 1145 |
+
.justify-end {
|
| 1146 |
+
justify-content: flex-end;
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
.justify-center {
|
| 1150 |
justify-content: center;
|
| 1151 |
}
|