Spaces:
Running
Running
shortening the name of files
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from src.do_pca_on_tfidf import query_docs
|
| 4 |
from src.search_embeddings import sbert_query_docs
|
| 5 |
import polars as pl
|
| 6 |
#from jinja2 import Template
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
@@ -36,13 +36,16 @@ def square(x: int):
|
|
| 36 |
|
| 37 |
|
| 38 |
@app.get("/search", response_class=JSONResponse)
|
| 39 |
-
|
| 40 |
res_tfidf = query_docs(q)
|
| 41 |
res_sbert = sbert_query_docs(q)
|
| 42 |
|
| 43 |
joined = res_sbert.join(res_tfidf, on='file', how = 'inner')
|
| 44 |
|
| 45 |
-
res_combined = joined.with_columns(
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
#return {"request": request, "results": str(res_combined)}
|
| 48 |
#return {"request": request, "results": res_combined.to_dicts()}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request, Query
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from src.do_pca_on_tfidf import query_docs
|
| 4 |
from src.search_embeddings import sbert_query_docs
|
| 5 |
import polars as pl
|
| 6 |
#from jinja2 import Template
|
| 7 |
|
| 8 |
+
path_prefix = "/Users/wes/Google Drive/Shared drives/datalab/projects/2025_coul_aisearch/data/original_box_download/"
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
@app.get("/search", response_class=JSONResponse)
|
| 39 |
+
def search(q: str = Query(..., description="Search query")):
|
| 40 |
res_tfidf = query_docs(q)
|
| 41 |
res_sbert = sbert_query_docs(q)
|
| 42 |
|
| 43 |
joined = res_sbert.join(res_tfidf, on='file', how = 'inner')
|
| 44 |
|
| 45 |
+
res_combined = joined.with_columns(
|
| 46 |
+
(0.7 * pl.col("rank-sbert") + 0.3 * pl.col("rank-tfidf")).alias("rank-combined"),
|
| 47 |
+
pl.col("file").removeprefix(path_prefix).alias("file")
|
| 48 |
+
).sort("rank-combined")
|
| 49 |
|
| 50 |
#return {"request": request, "results": str(res_combined)}
|
| 51 |
#return {"request": request, "results": res_combined.to_dicts()}
|