Skip to content

Commit ad2b530

Browse files
committed
fixed endpoint issues
1 parent 8f2f06a commit ad2b530

1 file changed

Lines changed: 13 additions & 29 deletions

File tree

src/webapp/routers/data.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import logging
1515
from sqlalchemy.exc import IntegrityError
1616
from ..config import databricks_vars, env_vars, gcs_vars
17+
from mlflow.exceptions import MlflowException
1718
import tempfile
1819
import pathlib
1920

@@ -1372,34 +1373,17 @@ def get_model_cards(
13721373
f"get_model_cards(): Workspace client initialization failed: {e}"
13731374
)
13741375

1375-
host = w.config.host # e.g. "https://12345.gcp.databricks.com"
1376-
1377-
# 2. Build the MLflow REST endpoint URL and params
1378-
download_endpoint = f"{host}/api/2.0/mlflow/artifacts/download"
1379-
artifact_path = f"model_card/model-card-{model_name}.pdf"
1380-
params = {"run_id": run_id, "path": artifact_path}
1381-
1382-
# 3. Let WorkspaceClient’s ApiClient perform the authenticated GET
13831376
try:
1384-
# perform_query will attach the same OAuth creds that WorkspaceClient uses
1385-
resp = w.api_client.perform_query( # type: ignore[attr-defined]
1386-
method="GET",
1387-
path=download_endpoint,
1388-
query_params=params,
1389-
) # type: ignore[attr-defined]
1390-
# resp here is the raw bytes of the PDF
1377+
volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf"
1378+
with w.files.download(volume_path) as stream:
1379+
pdf_bytes = stream.read()
13911380
except Exception as e:
1392-
raise HTTPException(
1393-
status_code=500,
1394-
detail=f"Could not download model card via MLflow REST API: {e}",
1395-
)
1396-
1397-
# 4. Write to a temp file and return it
1398-
with tempfile.TemporaryDirectory() as td:
1399-
out_path = pathlib.Path(td) / f"model-card-{model_name}.pdf"
1400-
out_path.write_bytes(resp)
1401-
return FileResponse(
1402-
path=str(out_path),
1403-
filename=out_path.name,
1404-
media_type="application/pdf",
1405-
)
1381+
raise HTTPException(500, detail=f"Failed to fetch model card: {e}")
1382+
1383+
# Stream back as FileResponse
1384+
tmp = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False)
1385+
tmp.write(pdf_bytes)
1386+
tmp.flush()
1387+
return FileResponse(
1388+
tmp.name, filename=tmp.name.split("/")[-1], media_type="application/pdf"
1389+
)

0 commit comments

Comments
 (0)