Skip to content

Commit 96928bf

Browse files
committed
put rapidoc assets in package
1 parent 82b53d6 commit 96928bf

8 files changed

Lines changed: 85 additions & 21 deletions

File tree

docs/_templates/layout.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% extends "!layout.html" %}
2+
3+
{% block menu %}
4+
{{ super() }}
5+
<a href="genindex.html">Index</a>
6+
{% endblock %}

vetiver/handlers/sklearn_vt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ def __init__(self, model, ptype_data, save_ptype):
1919
self.save_ptype = save_ptype
2020

2121
def create_description(self):
22-
"""Create description for sklearn model"""
23-
desc = f"Scikit-learn model of type {type(self.model)}"
22+
"""Create description for sklearn model
23+
"""
24+
desc = f"Scikit-learn {self.model.__class__} model"
2425
return desc
2526

2627
def vetiver_create_meta(

vetiver/rapidoc/highlight.min.js

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

vetiver/rapidoc/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=yes">
5+
<title>RapiDoc</title>
6+
<script type="module" src="https://unpkg.com/rapidoc@9.1.3/dist/rapidoc-min.js"></script>
7+
<link rel="stylesheet" href="./rapidoc/default.min.css">
8+
<script src="./rapidoc/highlight.min.js">
9+
</script></head>
10+
<body>
11+
<rapi-doc spec-url="{app.openapi_url}"
12+
id="thedoc" render-style="read" schema-style="tree"
13+
show-components="true" show-info="true" show-header="true"
14+
allow-search="true"
15+
show-side-nav="false"
16+
allow-authentication="false" update-route="false" match-type="regex"
17+
theme="light"
18+
header-color="#F2C6AC"
19+
primary-color = "#8C2D2D">
20+
<img
21+
slot="logo"
22+
width="55"
23+
src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/SVG/vetiver.svg"
24+
</rapi-doc>
25+
</body>
26+
</html>

vetiver/rapidoc/rapidoc-min.js

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

vetiver/server.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from fastapi import FastAPI, Request
22
from fastapi.responses import HTMLResponse
3+
from fastapi.staticfiles import StaticFiles
4+
from fastapi.openapi.utils import get_openapi
5+
36
import uvicorn
4-
from typing import Callable, Optional, Union, List
57
import requests
68
import pandas as pd
9+
from typing import Callable, Optional, Union, List
710

811
from .vetiver_model import VetiverModel
912
from .utils import _jupyter_nb
@@ -47,7 +50,9 @@ def __init__(
4750

4851
def _init_app(self):
4952
app = self.app_factory()
50-
53+
app.openapi = self._custom_openapi
54+
#app.mount("/static", StaticFiles(directory="static"), name="static")
55+
5156
@app.get("/", include_in_schema=False)
5257
async def main_app():
5358
return {"msg": "root path"}
@@ -56,7 +61,7 @@ async def main_app():
5661
# def docs_redirect():
5762
# return RedirectResponse("/rapidoc")
5863

59-
@app.get("/ping", include_in_schema=False)
64+
@app.get("/ping", include_in_schema=True)
6065
async def ping():
6166
return {"ping": "pong"}
6267

@@ -66,25 +71,34 @@ async def rapidoc():
6671
<!doctype html>
6772
<html>
6873
<head>
69-
<meta charset="utf-8">
70-
<script
71-
type="module"
72-
src="https://unpkg.com/rapidoc@9.1.4/dist/rapidoc-min.js"
73-
></script>
74-
</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>
7580
<body>
7681
<rapi-doc spec-url="{app.openapi_url}"
77-
theme="light"
78-
header-color="#0F4B71"
79-
primary-color = "#407483"
80-
schema-style="tree"
82+
id="thedoc"
8183
render-style="read"
8284
schema-style="tree"
83-
>
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">
8499
<img
85100
slot="logo"
86-
height="75"
87-
width="75"
101+
width="55"
88102
src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/SVG/vetiver.svg"
89103
</rapi-doc>
90104
</body>
@@ -159,6 +173,20 @@ def run(self):
159173
_jupyter_nb()
160174
uvicorn.run(self.app, port=self.port, host=self.host)
161175

176+
def _custom_openapi(self):
177+
if self.app.openapi_schema:
178+
return self.app.openapi_schema
179+
openapi_schema = get_openapi(
180+
title=self.model.name + " model API",
181+
version="0.1.3",
182+
description=self.model.description,
183+
routes=self.app.routes,
184+
)
185+
openapi_schema["info"]["x-logo"] = {
186+
"url": "../docs/figures/logo.svg"
187+
}
188+
self.app.openapi_schema = openapi_schema
189+
return self.app.openapi_schema
162190

163191
def predict(endpoint, data: dict, **kw):
164192
"""Make a prediction from model endpoint
@@ -214,3 +242,4 @@ def vetiver_endpoint(url="http://127.0.0.1:8000/predict"):
214242
URI path to endpoint
215243
"""
216244
return url
245+

vetiver/vetiver_model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ def __init__(
5757
self.save_ptype = save_ptype
5858
self.ptype = translator.ptype()
5959
self.model_name = model_name
60+
self.description = description if description else translator.create_description()
6061
self.versioned = versioned
61-
self.description = (
62-
translator.create_description() if description == None else description
63-
)
6462
self.metadata = translator.vetiver_create_meta(
6563
metadata, required_pkgs=["vetiver"]
6664
)

0 commit comments

Comments
 (0)