Spaces:
Running
Running
return results as JSON
Browse files
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
| 2 |
from src.do_pca_on_tfidf import query_docs
|
| 3 |
from src.search_embeddings import sbert_query_docs
|
| 4 |
import polars as pl
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 9 |
@app.get("/")
|
| 10 |
def default():
|
| 11 |
|
|
@@ -30,19 +34,17 @@ def tf(query: str):
|
|
| 30 |
def square(x: int):
|
| 31 |
return {"result": x * x}
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
joined = res_sbert.join(res_tfidf, on='file', how = 'inner')
|
| 39 |
|
| 40 |
res_combined = joined.with_columns((0.7 * pl.col("rank-sbert") + 0.3 * pl.col("rank-tfidf")).alias("rank-combined")).sort("rank-combined")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return {"result": res_combined.to_pandas().to_html(), "shape": res_combined.shape}
|
| 46 |
|
| 47 |
|
| 48 |
|
|
|
|
| 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 |
|
| 12 |
+
|
| 13 |
@app.get("/")
|
| 14 |
def default():
|
| 15 |
|
|
|
|
| 34 |
def square(x: int):
|
| 35 |
return {"result": x * x}
|
| 36 |
|
| 37 |
+
|
| 38 |
+
@app.get("/search", response_class=JSONResponse)
|
| 39 |
+
async def search(request: Request, q: str):
|
| 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((0.7 * pl.col("rank-sbert") + 0.3 * pl.col("rank-tfidf")).alias("rank-combined")).sort("rank-combined")
|
| 46 |
|
| 47 |
+
return {"request": request, "results": res_combined.to_dicts()}
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
|