MedhaCodes commited on
Commit
6b51665
·
verified ·
1 Parent(s): 7796b47

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +33 -8
app/main.py CHANGED
@@ -1,17 +1,42 @@
1
- from fastapi import FastAPI, UploadFile, File
 
 
 
2
  from PIL import Image
3
  import io
4
 
5
- from app.inference import predict_image
 
 
 
 
6
 
7
  app = FastAPI()
8
 
9
- @app.get("/")
10
- def root():
11
- return {"status": "Plant Disease API running"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  @app.post("/predict")
14
  async def predict(file: UploadFile = File(...)):
15
- image_bytes = await file.read()
16
- image = Image.open(io.BytesIO(image_bytes))
17
- return predict_image(image)
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File, Request
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.templating import Jinja2Templates
5
  from PIL import Image
6
  import io
7
 
8
+
9
+
10
+ from app.predict import predict_pil_image
11
+
12
+
13
 
14
  app = FastAPI()
15
 
16
+
17
+
18
+ app.mount("/static", StaticFiles(directory="static"), name="static")
19
+ templates = Jinja2Templates(directory="templates")
20
+
21
+
22
+
23
+
24
+
25
+
26
+ @app.get("/", response_class=HTMLResponse)
27
+ def home(request: Request):
28
+ return templates.TemplateResponse("index.html", {"request": request})
29
+
30
+
31
+
32
+
33
+
34
 
35
  @app.post("/predict")
36
  async def predict(file: UploadFile = File(...)):
37
+ image_bytes = await file.read()
38
+ image = Image.open(io.BytesIO(image_bytes))
39
+ return predict_pil_image(image)
40
+
41
+
42
+