-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathParameters.py
48 lines (39 loc) · 1.26 KB
/
PathParameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import nest_asyncio
from pyngrok import ngrok
import uvicorn
from enum import Enum
app = FastAPI()
# Accepting only pre-defined values as the parameter value using python Enum.
class ModelName(str, Enum):
alexnet = "alexnet"
resnet = "resnet"
lenet = "lenet"
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.get('/items/{item_id}')
async def read_item(item_id : int):
return { "item_id": {item_id}}
@app.get('/user/me')
async def read_user():
return {"UserName" : "The Current user"}
@app.get('/user/{user_id}')
async def read_user(user_id : str):
return {"UserName" : {user_id}}
@app.get("/model/{model_name}")
async def get_model(model_name: ModelName):
if model_name == ModelName.alexnet:
return {"model_name": model_name, "message": "Deep Learning FTW!"}
if model_name == ModelName.lenet:
return {"model_name": model_name, "message": "LeCNN all the images"}
return {"model_name": model_name, "message": "Have some residuals"}
ngrok_tunnel = ngrok.connect(8000)
print('Public URL:', ngrok_tunnel.public_url)
nest_asyncio.apply()
uvicorn.run(app, port=8000)