itsHamza commited on
Commit
205a1c4
·
verified ·
1 Parent(s): 59073db

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +13 -0
  2. app.py +30 -0
  3. growlens_efficientnet_model.h5 +3 -0
  4. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py .
9
+ COPY growlens_efficientnet_model.h5 .
10
+
11
+ EXPOSE 7860
12
+
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from fastapi.responses import JSONResponse
3
+ import tensorflow as tf
4
+ from PIL import Image
5
+ import numpy as np
6
+ import io
7
+
8
+ app = FastAPI()
9
+
10
+ # Load model
11
+ def load_model():
12
+ return tf.keras.models.load_model("growlens_efficientnet_model.h5")
13
+
14
+ model = load_model()
15
+ class_names = [
16
+ "ants", "bees", "beetle", "catterpillar", "earthworms", "earwig",
17
+ "grasshopper", "moth", "slug", "snail", "wasp", "weevil"
18
+ ]
19
+
20
+ @app.post("/predict")
21
+ async def predict(file: UploadFile = File(...)):
22
+ image_bytes = await file.read()
23
+ image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
24
+ image = image.resize((224, 224)) # Adjust size as per your model
25
+ img_array = np.array(image) / 255.0
26
+ img_array = np.expand_dims(img_array, axis=0)
27
+ preds = model.predict(img_array)
28
+ pred_class = class_names[np.argmax(preds)]
29
+ confidence = float(np.max(preds))
30
+ return JSONResponse({"class": pred_class, "confidence": confidence})
growlens_efficientnet_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad68ad756d68ad00f95fdd40882781eb4a9c64c3fcd7ce7c7178e2d3d1057c3d
3
+ size 20906560
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ tensorflow
4
+ pillow
5
+ numpy