Spaces:
Sleeping
Sleeping
Download src/mlops/tracking.py from makdadTaleb/rag-lecture-saver-api: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/makdadTaleb/rag-lecture-saver-api/resolve/main/src/mlops/tracking.py
- Command line
-
hf download hf://spaces/makdadTaleb/rag-lecture-saver-api/src/mlops/tracking.py
-
curl -L -o tracking.py https://huggingface.co/spaces/makdadTaleb/rag-lecture-saver-api/resolve/main/src/mlops/tracking.py
1.01 kB
| import mlflow | |
| from pathlib import Path | |
| import faiss | |
| from contextlib import contextmanager | |
| def start_experiment(experiment_name: str): | |
| mlflow.set_experiment(experiment_name) | |
| mlflow.start_run() | |
| def init_mlflow(experiment_name: str): | |
| mlflow.set_experiment(experiment_name) | |
| def start_rag_run(run_name: str = "rag_query"): | |
| with mlflow.start_run(run_name=run_name): | |
| yield | |
| def log_params_dict(params: dict): | |
| for k, v in params.items(): | |
| mlflow.log_param(k, v) | |
| def log_metrics_dict(metrics: dict): | |
| for k, v in metrics.items(): | |
| mlflow.log_metric(k, v) | |
| def log_text_artifact(text: str, artifact_path: str): | |
| mlflow.log_text(text, artifact_path) | |
| def log_faiss_index(index, path: Path): | |
| faiss.write_index(index, str(path)) | |
| mlflow.log_artifact(str(path)) | |
| def log_artifact_metadatas(metadatas: Path ="metadata.json"): | |
| mlflow.log_artifact(str(metadatas)) | |
| def end_run(): | |
| mlflow.end_run() | |