eaedk commited on
Commit
e8f8734
1 Parent(s): 473519c

update to include the root endpoint

Browse files
Files changed (1) hide show
  1. src/main.py +23 -2
src/main.py CHANGED
@@ -1,9 +1,24 @@
1
- from fastapi import FastAPI, HTTPException
 
 
 
2
  from pydantic import BaseModel, validator
3
  import pandas as pd
4
  import pickle, uvicorn, os, logging
5
 
6
- app = FastAPI()
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Configure logging
9
  logging.basicConfig(level=logging.INFO)
@@ -109,5 +124,11 @@ async def predict_price(device_id: int, specs: DeviceSpecs):
109
  raise HTTPException(status_code=500, detail=str(e))
110
 
111
 
 
 
 
 
 
 
112
  if __name__ == "__main__":
113
  uvicorn.run(app, host="127.0.0.1", port=8000, reload=True)
 
1
+ from fastapi import FastAPI, HTTPException, Request
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.templating import Jinja2Templates
5
  from pydantic import BaseModel, validator
6
  import pandas as pd
7
  import pickle, uvicorn, os, logging
8
 
9
+
10
+ # API Config
11
+ app = FastAPI(
12
+ # title="Agri-Tech API",
13
+ # description="This is a ML API for classification of crop to plant on a land regarding some features",
14
+ )
15
+
16
+ ## Configure static and template files
17
+ app.mount(
18
+ "/static", StaticFiles(directory="assets/static"), name="static"
19
+ ) # Mount static files
20
+ templates = Jinja2Templates(directory="assets/templates") # Mount templates for HTML
21
+
22
 
23
  # Configure logging
24
  logging.basicConfig(level=logging.INFO)
 
124
  raise HTTPException(status_code=500, detail=str(e))
125
 
126
 
127
+ # Root endpoint to serve index.html template
128
+ @app.get("/", response_class=HTMLResponse)
129
+ async def root(request: Request):
130
+ return templates.TemplateResponse("index.html", {"request": request})
131
+
132
+
133
  if __name__ == "__main__":
134
  uvicorn.run(app, host="127.0.0.1", port=8000, reload=True)