Spaces:
Sleeping
Sleeping
added: app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Form, Depends, Request
|
| 2 |
+
from fastapi.templating import Jinja2Templates
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
import pickle
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# Menentukan direktori templates
|
| 10 |
+
templates = Jinja2Templates(directory="templates")
|
| 11 |
+
|
| 12 |
+
class Msg(BaseModel):
|
| 13 |
+
msg: str
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class Req(BaseModel):
|
| 17 |
+
age: int
|
| 18 |
+
sex: int
|
| 19 |
+
smoker: int
|
| 20 |
+
bmi: float
|
| 21 |
+
children: int
|
| 22 |
+
region: int
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@app.get("/welcomeMessage")
|
| 26 |
+
async def welcome():
|
| 27 |
+
return {"message": "Hello World. Welcome to FastAPI!"}
|
| 28 |
+
|
| 29 |
+
@app.get("/")
|
| 30 |
+
async def root(request: Request):
|
| 31 |
+
return templates.TemplateResponse(
|
| 32 |
+
"index.html",
|
| 33 |
+
{
|
| 34 |
+
"request": request,
|
| 35 |
+
"insurance_cost": 0,
|
| 36 |
+
}
|
| 37 |
+
)
|