Skip to content

Commit 0b04b8e

Browse files
committed
first iteration for matching
1 parent 96928bf commit 0b04b8e

7 files changed

Lines changed: 108 additions & 83 deletions

File tree

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
<<<<<<< HEAD
12
include vetiver/data/*.csv
3+
=======
4+
include vetiver/rapidoc/*.js
5+
include vetiver/rapidoc/*.css
6+
>>>>>>> e4733af (first iteration for matching)

docs/_templates/layout.html

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vetiver.VetiverModel.\_\_init\_\_
2+
=================================
3+
4+
.. currentmodule:: vetiver
5+
6+
.. automethod:: VetiverModel.__init__

vetiver/rapidoc/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from importlib_resources import files as _files
2+
3+
sources = {
4+
"default_css": _files("vetiver") / "rapidoc/default.min.css",
5+
"highlight": _files("vetiver") / "rapidoc/highligh.min.js",
6+
"rapidoc": _files("vetiver") / "rapidoc/rapidoc-min.js",
7+
}
8+
9+
10+
def __dir__():
11+
return list(sources)
12+
13+
14+
def __getattr__(k):
15+
f_path = sources.get(k)
16+
17+
return f_path

vetiver/rapidoc/index.html

Lines changed: 0 additions & 26 deletions
This file was deleted.

vetiver/server.py

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from fastapi import FastAPI, Request
2-
from fastapi.responses import HTMLResponse
2+
from fastapi.responses import HTMLResponse, RedirectResponse
33
from fastapi.staticfiles import StaticFiles
44
from fastapi.openapi.utils import get_openapi
55

@@ -10,6 +10,7 @@
1010

1111
from .vetiver_model import VetiverModel
1212
from .utils import _jupyter_nb
13+
from vetiver import rapidoc
1314

1415

1516
class 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
191177
def 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-

vetiver/templates/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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="../rapidoc/rapidoc-min.js"></script>
7+
<link rel="stylesheet" href="../rapidoc/default.min.css"></link>
8+
<script src="../rapidoc/highlight.min.js"></script>
9+
</script></head>
10+
<body>
11+
<rapi-doc spec-url="/openapi.json"
12+
id="thedoc"
13+
render-style="read"
14+
schema-style="tree"
15+
show-components="false"
16+
show-info="true"
17+
show-header="true"
18+
show-spec-url="false"
19+
allow-search="true"
20+
allow-advanced-search="true"
21+
show-side-nav="false"
22+
allow-authentication="false"
23+
allow-api-list-style-selection="false"
24+
update-route="false"
25+
match-type="regex"
26+
theme="light"
27+
header-color="#F2C6AC"
28+
primary-color = "#8C2D2D">
29+
<img
30+
slot="logo"
31+
width="55"
32+
src="../../docs/figures/logo.svg"
33+
</rapi-doc>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)