11from fastapi import FastAPI , Request
2- from fastapi .responses import HTMLResponse
2+ from fastapi .responses import HTMLResponse , RedirectResponse
33from fastapi .staticfiles import StaticFiles
44from fastapi .openapi .utils import get_openapi
55
1010
1111from .vetiver_model import VetiverModel
1212from .utils import _jupyter_nb
13+ from vetiver import rapidoc
1314
1415
1516class VetiverAPI :
@@ -51,58 +52,44 @@ def __init__(
5152 def _init_app (self ):
5253 app = self .app_factory ()
5354 app .openapi = self ._custom_openapi
54- #app.mount("/static", StaticFiles(directory="static"), name="static")
55-
56- @app .get ("/" , include_in_schema = False )
57- async def main_app ():
58- return {"msg" : "root path" }
5955
60- # redirect to docs?
61- # def docs_redirect():
62- # return RedirectResponse("/rapidoc ")
56+ @ app . get ( "/" , include_in_schema = False )
57+ def docs_redirect ():
58+ return RedirectResponse ("/__docs__ " )
6359
6460 @app .get ("/ping" , include_in_schema = True )
6561 async def ping ():
6662 return {"ping" : "pong" }
6763
68- @app .get ("/rapidoc " , response_class = HTMLResponse , include_in_schema = False )
69- async def rapidoc ():
64+ @app .get ("/__docs__ " , response_class = HTMLResponse , include_in_schema = False )
65+ async def rapidoc_pg ():
7066 return f"""
71- <!doctype html>
72- <html>
73- <head>
74- <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=yes">
75- <title>RapiDoc</title>
76- <script type="module" src="https://unpkg.com/rapidoc@9.1.3/dist/rapidoc-min.js">
77- <link rel="stylesheet" href="./rapidoc/default.min.css"></link>
78- <script src="./rapidoc/highlight.min.js"></script>
79- </script></head>
80- <body>
81- <rapi-doc spec-url="{ app .openapi_url } "
82- id="thedoc"
83- render-style="read"
84- schema-style="tree"
85- show-components="false"
86- show-info="true"
87- show-header="true"
88- show-spec-url="false"
89- allow-search="true"
90- allow-advanced-search="true"
91- show-side-nav="false"
92- allow-authentication="false"
93- allow-api-list-style-selection="false"
94- update-route="false"
95- match-type="regex"
96- theme="light"
97- header-color="#F2C6AC"
98- primary-color = "#8C2D2D">
99- <img
100- slot="logo"
101- width="55"
102- src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/SVG/vetiver.svg"
103- </rapi-doc>
104- </body>
105- </html>
67+ <!doctype html>
68+ <html>
69+ <head>
70+ <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=yes">
71+ <title>RapiDoc</title>
72+ <script type="module" src="https://unpkg.com/rapidoc@9.1.3/dist/rapidoc-min.js"></script>
73+ <link rel="stylesheet" href="./rapidoc/default.min.css">
74+ <script src="./rapidoc/highlight.min.js">
75+ </script></head>
76+ <body>
77+ <rapi-doc spec-url="{ app .openapi_url } "
78+ id="thedoc" render-style="read" schema-style="tree"
79+ show-components="true" show-info="true" show-header="true"
80+ allow-search="true"
81+ show-side-nav="false"
82+ allow-authentication="false" update-route="false" match-type="regex"
83+ theme="light"
84+ header-color="#F2C6AC"
85+ primary-color = "#8C2D2D">
86+ <img
87+ slot="logo"
88+ width="55"
89+ src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/SVG/vetiver.svg"
90+ </rapi-doc>
91+ </body>
92+ </html>
10693 """
10794
10895 if self .check_ptype == True :
@@ -177,18 +164,21 @@ def _custom_openapi(self):
177164 if self .app .openapi_schema :
178165 return self .app .openapi_schema
179166 openapi_schema = get_openapi (
180- title = self .model .name + " model API" ,
167+ title = self .model .model_name + " model API" ,
181168 version = "0.1.3" ,
182169 description = self .model .description ,
183170 routes = self .app .routes ,
184171 )
185- openapi_schema ["info" ]["x-logo" ] = {
186- "url" : "../docs/figures/logo.svg"
187- }
172+ openapi_schema ["info" ]["x-logo" ] = {"url" : "../docs/figures/logo.svg" }
188173 self .app .openapi_schema = openapi_schema
189174 return self .app .openapi_schema
190175
176+ < << << << HEAD
191177def predict (endpoint , data : dict , ** kw ):
178+ == == == =
179+
180+ def predict (endpoint , data : dict ):
181+ > >> >> >> e4733af (first iteration for matching )
192182 """Make a prediction from model endpoint
193183
194184 Parameters
@@ -205,9 +195,14 @@ def predict(endpoint, data: dict, **kw):
205195 """
206196 if isinstance (data , pd .DataFrame ):
207197 data = data .to_json (orient = "records" )
198+ < << << << HEAD
208199 response = requests .post (endpoint , data = data , ** kw )
209200 else :
210201 response = requests .post (endpoint , json = data , ** kw )
202+ == == == =
203+
204+ response = requests .post (endpoint , data = data )
205+ >> >> >> > e4733af (first iteration for matching )
211206
212207 return response .json ()
213208
@@ -242,4 +237,3 @@ def vetiver_endpoint(url="http://127.0.0.1:8000/predict"):
242237 URI path to endpoint
243238 """
244239 return url
245-
0 commit comments