Spaces:
Running
Running
removed some cruft from app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from src.embeddings_search import create_embeddings_search_function_from_embeddings_df
|
| 4 |
from src.tfidf_search import create_tfidf_search_function
|
|
@@ -13,52 +13,28 @@ path_prefix = "/Users/wes/Google Drive/Shared drives/datalab/projects/2025_coul_
|
|
| 13 |
block_embeddings_df_path = "block_embeddings/block-embeddings.parquet"
|
| 14 |
doc_tfidf_df_path = "block_tfidf/TF-IDF-doc-text.parquet"
|
| 15 |
tfidf_vectorizer_path = "block_tfidf/tfidf_vectorizer_doc_text.joblib"
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
app = FastAPI()
|
| 19 |
|
| 20 |
|
| 21 |
@app.get("/")
|
| 22 |
def default():
|
| 23 |
-
|
| 24 |
return {"status": "ok", "version": 0.1}
|
| 25 |
|
| 26 |
|
| 27 |
-
@app.get("/sbert")
|
| 28 |
-
def sb(query: str):
|
| 29 |
-
res_sbert = sbert_query_docs(query)
|
| 30 |
-
|
| 31 |
-
return {"scores": str(res_sbert)}
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
@app.get("/tfidf")
|
| 35 |
-
def tf(query: str):
|
| 36 |
-
res_tfidf = query_docs(query)
|
| 37 |
-
|
| 38 |
-
return {"scores": str(res_tfidf)}
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@app.get("/square")
|
| 42 |
-
def square(x: int):
|
| 43 |
-
return {"result": x * x}
|
| 44 |
-
|
| 45 |
-
|
| 46 |
@app.get("/search", response_class=JSONResponse)
|
| 47 |
def search(q: str = Query(..., description="Search query")):
|
| 48 |
-
block_embeddings_df_path = "block_embeddings/block-embeddings.parquet"
|
| 49 |
-
doc_tfidf_df_path = "block_tfidf/TF-IDF-doc-text.parquet"
|
| 50 |
-
tfidf_vectorizer_path = "block_tfidf/tfidf_vectorizer_doc_text.joblib"
|
| 51 |
-
|
| 52 |
-
sbert_query_docs = create_embeddings_search_function_from_embeddings_df(
|
| 53 |
-
model_name = "sentence-transformers/all-MiniLM-L6-v2",
|
| 54 |
-
embeddings_df_path = block_embeddings_df_path,
|
| 55 |
-
device = "cpu")
|
| 56 |
-
tfidf_query_docs = create_tfidf_search_function(
|
| 57 |
-
dtm_df_path = doc_tfidf_df_path,
|
| 58 |
-
vectorizer_path = tfidf_vectorizer_path,
|
| 59 |
-
model_name = "facebook/fasttext-en-vectors")
|
| 60 |
-
|
| 61 |
-
|
| 62 |
res_tfidf = tfidf_query_docs(q)
|
| 63 |
res_sbert = sbert_query_docs(q)
|
| 64 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Query
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
from src.embeddings_search import create_embeddings_search_function_from_embeddings_df
|
| 4 |
from src.tfidf_search import create_tfidf_search_function
|
|
|
|
| 13 |
block_embeddings_df_path = "block_embeddings/block-embeddings.parquet"
|
| 14 |
doc_tfidf_df_path = "block_tfidf/TF-IDF-doc-text.parquet"
|
| 15 |
tfidf_vectorizer_path = "block_tfidf/tfidf_vectorizer_doc_text.joblib"
|
| 16 |
+
|
| 17 |
+
sbert_query_docs = create_embeddings_search_function_from_embeddings_df(
|
| 18 |
+
model_name = "sentence-transformers/all-MiniLM-L6-v2",
|
| 19 |
+
embeddings_df_path = block_embeddings_df_path,
|
| 20 |
+
device = "cpu")
|
| 21 |
+
tfidf_query_docs = create_tfidf_search_function(
|
| 22 |
+
dtm_df_path = doc_tfidf_df_path,
|
| 23 |
+
vectorizer_path = tfidf_vectorizer_path,
|
| 24 |
+
model_name = "facebook/fasttext-en-vectors")
|
| 25 |
+
|
| 26 |
+
print("generated the search functions!")
|
| 27 |
|
| 28 |
app = FastAPI()
|
| 29 |
|
| 30 |
|
| 31 |
@app.get("/")
|
| 32 |
def default():
|
|
|
|
| 33 |
return {"status": "ok", "version": 0.1}
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
@app.get("/search", response_class=JSONResponse)
|
| 37 |
def search(q: str = Query(..., description="Search query")):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
res_tfidf = tfidf_query_docs(q)
|
| 39 |
res_sbert = sbert_query_docs(q)
|
| 40 |
|