|
'''
|
|
purpose: fastAPI routing
|
|
|
|
refs:
|
|
fast api behind proxy/root_path: https://fastapi.tiangolo.com/advanced/behind-a-proxy/
|
|
'''
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
from fastapi import APIRouter, Request, Response
|
|
from fastapi.templating import Jinja2Templates
|
|
import uvicorn
|
|
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
description = """
|
|
Prototype: FastApi in Docker on Huggingface
|
|
|
|
<insert purpose>
|
|
|
|
## key business benefit #1
|
|
## key business benefit #2
|
|
## key business benefit #3
|
|
|
|
You will be able to:
|
|
* key feature #1
|
|
* key feature #2
|
|
* key feature #3
|
|
"""
|
|
|
|
|
|
app = FastAPI(
|
|
title="Prototype: Fastapi in docker",
|
|
description=description,
|
|
version="0.0.1",
|
|
terms_of_service="http://example.com/terms/",
|
|
contact={
|
|
"name": "Iain McKone",
|
|
"email": "[email protected]",
|
|
},
|
|
license_info={
|
|
"name": "MIT",
|
|
"url": "http://opensource.org/licenses/MIT",
|
|
},
|
|
openapi_url="/api/v1/openapi.json"
|
|
)
|
|
|
|
io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
|
|
app = gr.mount_gradio_app(app, io, path="/gradio_svc")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" def get_jinja2Templ(request: Request, pdfResults, strParamTitle, lngNumRecords, blnIsTrain=False, blnIsSample=False):
|
|
lngNumRecords = min(lngNumRecords, libUtils.m_klngMaxRecords)
|
|
if (blnIsTrain): strParamTitle = strParamTitle + " - Training Data"
|
|
if (not blnIsTrain): strParamTitle = strParamTitle + " - Test Data"
|
|
if (blnIsSample): lngNumRecords = libUtils.m_klngSampleSize
|
|
strParamTitle = strParamTitle + " - max " + str(lngNumRecords) + " rows"
|
|
|
|
kstrTempl = 'templ_showDataframe.html'
|
|
jsonContext = {'request': request,
|
|
'paramTitle': strParamTitle,
|
|
'paramDataframe': pdfResults.sample(lngNumRecords).to_html(classes='table table-striped')
|
|
}
|
|
result = m_templRef.TemplateResponse(kstrTempl, jsonContext)
|
|
return result """
|
|
|
|
|
|
|
|
@app.get('/')
|
|
def index():
|
|
|
|
return {
|
|
"message": "Landing page: prototype for fastApi"
|
|
}
|
|
|
|
@app.get('/api')
|
|
def rte_api():
|
|
|
|
return {
|
|
"message": "Landing page: prototype for fastApi"
|
|
}
|
|
|
|
@app.get('/gradio')
|
|
def rte_gradio():
|
|
|
|
|
|
|
|
|
|
return RedirectResponse("/gradio_svc")
|
|
|
|
|
|
@app.get('/streamlit')
|
|
def rte_streamlit():
|
|
|
|
return {
|
|
"message": "Landing page: this is where streamlit would start from if we could mount with fastapi"
|
|
}
|
|
|
|
@app.get('/shiny')
|
|
def rte_shiny():
|
|
|
|
return {
|
|
"message": "Landing page: this is where shiny would start mounted with fastapi"
|
|
}
|
|
|
|
@app.get('/syscheck/{check_id}')
|
|
async def syscheck(check_id: str):
|
|
from os import system
|
|
|
|
|
|
print("TRACE: fastapi.syscheck ... {check_id} ", check_id)
|
|
|
|
if (check_id=='apt_list'):
|
|
print("TRACE: fastapi.syscheck ... {apt_list} ")
|
|
m_sysMsg = system("apt list --installed")
|
|
return {"message: syscheck apt list complete " + str(m_sysMsg)}
|
|
|
|
elif (check_id=='sanity'):
|
|
print("TRACE: fastapi.syscheck ... {}".format(check_id))
|
|
return {"message: syscheck sanity ... ok "}
|
|
|
|
elif (check_id=='pip_list'):
|
|
print("TRACE: fastapi.syscheck ... {pip_list} ")
|
|
m_sysMsg = system("pip list")
|
|
return {"message: syscheck pip list complete " + str(m_sysMsg)}
|
|
|
|
else:
|
|
return {"message": "fastApi: syscheck {check_id} " + check_id}
|
|
|
|
|
|
@app.get('/sanity')
|
|
async def sanity():
|
|
print("TRACE: fastapi.sanity ... {}")
|
|
return {"message: syscheck sanity ... ok "}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
uvicorn.run("fastapi.entry_fastapi:app", reload=True, workers=1, host="0.0.0.0", port=49132)
|
|
|
|
|
|
|