Commit ·
a2d40e3
1
Parent(s): 2995c02
Refactor predict_rows function to include raw predictions
Browse filesThis commit refactors the predict_rows function in main.py to include an optional parameter, return_raw_predictions, which when set to True, returns the raw predictions along with the mean scores. This change improves the flexibility and usefulness of the function.
180 unmodified lines1811821831841851861876 unmodified lines194195196197198199200201202180 unmodified linesreturn {k for k, v in counts_dict.items() if v >= threshold}def predict_rows(rows, target_column, language_threshold_percent=0.2):rows = (row.get(target_column) for row in rows)rows = (row for row in rows if row is not None)rows = list(yield_clean_rows(rows))6 unmodified lineslangues_counts, threshold_percent=language_threshold_percent)filtered_dict = {k: v for k, v in predictions_by_lang.items() if k in keys_to_keep}return {"predictions": dict(valmap(get_mean_score, filtered_dict)),}@app.get("/", include_in_schema=False)180 unmodified lines1811821831841851861871881896 unmodified lines196197198199200201202203204205206207208209210211212213214215180 unmodified linesreturn {k for k, v in counts_dict.items() if v >= threshold}def predict_rows(rows, target_column, language_threshold_percent=0.2, return_raw_predictions=False):rows = (row.get(target_column) for row in rows)rows = (row for row in rows if row is not None)rows = list(yield_clean_rows(rows))6 unmodified lineslangues_counts, threshold_percent=language_threshold_percent)filtered_dict = {k: v for k, v in predictions_by_lang.items() if k in keys_to_keep}default_data = {"predictions": dict(valmap(get_mean_score, filtered_dict)),"hub_id": "hub_id","config": "config",}if return_raw_predictions:default_data["raw_predictions"] = predictionsreturn default_data# @app.get("/", response_class=HTMLResponse)# async def read_index():# html_content = Path("index.html").read_text()# return HTMLResponse(content=html_content)@app.get("/", include_in_schema=False)
main.py+15-2