1- from typing import Callable , List , Union
2- from urllib .parse import urljoin
3-
41import re
52import httpx
63import json
7- import pandas as pd
84import requests
95import uvicorn
6+ import logging
7+ import pandas as pd
108from fastapi import FastAPI , Request , testclient
119from fastapi .exceptions import RequestValidationError
1210from fastapi .openapi .utils import get_openapi
13- from fastapi .responses import HTMLResponse , RedirectResponse
14- from fastapi .responses import PlainTextResponse
11+ from fastapi .responses import HTMLResponse , RedirectResponse , PlainTextResponse
1512from textwrap import dedent
1613from warnings import warn
14+ from urllib .parse import urljoin
15+ from typing import Callable , List , Union
1716
18- from .utils import _jupyter_nb
17+ from .utils import _jupyter_nb , get_workbench_path
1918from .vetiver_model import VetiverModel
2019from .meta import VetiverMeta
2120from .helpers import api_data_to_frame , response_to_frame
@@ -71,6 +70,7 @@ def __init__(
7170 self .model = model
7271 self .app_factory = app_factory
7372 self .app = app_factory ()
73+ self .workbench_path = None
7474
7575 if "check_ptype" in kwargs :
7676 check_prototype = kwargs .pop ("check_ptype" )
@@ -93,6 +93,14 @@ def _init_app(self):
9393 app = self .app
9494 app .openapi = self ._custom_openapi
9595
96+ @app .on_event ("startup" )
97+ async def startup_event ():
98+ logger = logging .getLogger ("uvicorn.error" )
99+ if self .workbench_path :
100+ logger .info (f"VetiverAPI starting at { self .workbench_path } " )
101+ else :
102+ logger .info ("VetiverAPI starting..." )
103+
96104 @app .get ("/" , include_in_schema = False )
97105 def docs_redirect ():
98106
@@ -261,7 +269,14 @@ def run(self, port: int = 8000, host: str = "127.0.0.1", **kw):
261269 >>> v_api.run() # doctest: +SKIP
262270 """
263271 _jupyter_nb ()
264- uvicorn .run (self .app , port = port , host = host , ** kw )
272+ self .workbench_path = get_workbench_path (port )
273+
274+ if self .workbench_path :
275+ uvicorn .run (
276+ self .app , port = port , host = host , root_path = self .workbench_path , ** kw
277+ )
278+ else :
279+ uvicorn .run (self .app , port = port , host = host , ** kw )
265280
266281 def _custom_openapi (self ):
267282 import vetiver
0 commit comments