Commit
•
76a283e
1
Parent(s):
28a6437
Add logging and comment out unused code
Browse files
main.py
CHANGED
@@ -14,12 +14,14 @@ from toolz import concat, groupby, valmap
|
|
14 |
from starlette.responses import RedirectResponse
|
15 |
from cashews import cache
|
16 |
from datetime import timedelta
|
|
|
17 |
|
18 |
cache.setup("mem://")
|
19 |
|
20 |
|
|
|
21 |
app = FastAPI()
|
22 |
-
logger = logging.get_logger(__name__)
|
23 |
load_dotenv()
|
24 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
25 |
|
@@ -127,9 +129,9 @@ def load_model(repo_id: str) -> fasttext.FastText._FastText:
|
|
127 |
model_path = hf_hub_download(
|
128 |
repo_id,
|
129 |
"model.bin",
|
130 |
-
cache_dir="code/models",
|
131 |
-
local_dir="code/models",
|
132 |
-
local_dir_use_symlinks=False,
|
133 |
)
|
134 |
return fasttext.load_model(model_path)
|
135 |
|
@@ -194,22 +196,15 @@ def predict_rows(rows, target_column, language_threshold_percent=0.2):
|
|
194 |
filtered_dict = {k: v for k, v in predictions_by_lang.items() if k in keys_to_keep}
|
195 |
return {
|
196 |
"predictions": dict(valmap(get_mean_score, filtered_dict)),
|
197 |
-
"pred": predictions,
|
198 |
}
|
199 |
|
200 |
|
201 |
-
# @app.get("/", response_class=HTMLResponse)
|
202 |
-
# async def read_index():
|
203 |
-
# html_content = Path("index.html").read_text()
|
204 |
-
# return HTMLResponse(content=html_content)
|
205 |
-
|
206 |
-
|
207 |
@app.get("/", include_in_schema=False)
|
208 |
def root():
|
209 |
return RedirectResponse(url="/docs")
|
210 |
|
211 |
|
212 |
-
@app.get("/predict_dataset_language/{hub_id}")
|
213 |
@cache(ttl=timedelta(minutes=10))
|
214 |
async def predict_language(
|
215 |
hub_id: str,
|
|
|
14 |
from starlette.responses import RedirectResponse
|
15 |
from cashews import cache
|
16 |
from datetime import timedelta
|
17 |
+
import logging
|
18 |
|
19 |
cache.setup("mem://")
|
20 |
|
21 |
|
22 |
+
logger = logging.getLogger(__name__)
|
23 |
app = FastAPI()
|
24 |
+
# logger = logging.get_logger(__name__)
|
25 |
load_dotenv()
|
26 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
27 |
|
|
|
129 |
model_path = hf_hub_download(
|
130 |
repo_id,
|
131 |
"model.bin",
|
132 |
+
# cache_dir="code/models",
|
133 |
+
# local_dir="code/models",
|
134 |
+
# local_dir_use_symlinks=False,
|
135 |
)
|
136 |
return fasttext.load_model(model_path)
|
137 |
|
|
|
196 |
filtered_dict = {k: v for k, v in predictions_by_lang.items() if k in keys_to_keep}
|
197 |
return {
|
198 |
"predictions": dict(valmap(get_mean_score, filtered_dict)),
|
|
|
199 |
}
|
200 |
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
@app.get("/", include_in_schema=False)
|
203 |
def root():
|
204 |
return RedirectResponse(url="/docs")
|
205 |
|
206 |
|
207 |
+
@app.get("/predict_dataset_language/{hub_id:path}")
|
208 |
@cache(ttl=timedelta(minutes=10))
|
209 |
async def predict_language(
|
210 |
hub_id: str,
|