Skip to content

Commit a3ed8f2

Browse files
upload to huggingface via cli, mlflow build docker image make script
1 parent 4b0a7e2 commit a3ed8f2

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "intent-service"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
description = "Intent classification service"
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -21,7 +21,7 @@ classifiers = [
2121
dependencies = [
2222
"fastapi>=0.68.0,<1.0.0",
2323
"pydantic>=2.4.2,<3.0.0",
24-
"mlflow>=2.10.1",
24+
"mlflow>=2.18.0",
2525
"polars>=0.20.0",
2626
"uvicorn>=0.15.0",
2727
"requests==2.31.0",

src/api/endpoints.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import json
55
import multiprocessing
6+
import os
67
import queue
78
from multiprocessing.queues import Queue
89
from multiprocessing.synchronize import Event
@@ -746,19 +747,28 @@ async def predict(model_id: str, text: str) -> dict:
746747
"""
747748
try:
748749
# First try loading as a registered model
749-
try:
750-
loaded_model = mlflow.pyfunc.load_model(f"models:/{model_id}/latest")
751-
except mlflow.exceptions.MlflowException:
752-
# If not found as registered model, try loading as a run
750+
dst_path = f"model_cache/{model_id}"
751+
if model_id in os.listdir("model_cache"):
752+
loaded_model = mlflow.pyfunc.load_model(dst_path)
753+
else:
754+
os.makedirs(dst_path, exist_ok=True)
753755
try:
754756
loaded_model = mlflow.pyfunc.load_model(
755-
f"runs:/{model_id}/intent_model"
757+
f"models:/{model_id}/latest",
758+
dst_path=dst_path,
756759
)
757760
except mlflow.exceptions.MlflowException:
758-
raise HTTPException(
759-
status_code=404,
760-
detail=f"No model found with ID {model_id} (tried both registered models and runs)",
761-
)
761+
# If not found as registered model, try loading as a run
762+
try:
763+
loaded_model = mlflow.pyfunc.load_model(
764+
f"runs:/{model_id}/intent_model",
765+
dst_path=dst_path,
766+
)
767+
except mlflow.exceptions.MlflowException:
768+
raise HTTPException(
769+
status_code=404,
770+
detail=f"No model found with ID {model_id} (tried both registered models and runs)",
771+
)
762772

763773
# Create a pandas DataFrame with the input text
764774
test_data = pd.DataFrame({"text": [text]})

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)