Spaces:
Build error
Build error
add files
Browse files- CNN_TEA_MODEL.h5 +3 -0
- Dockerfile +10 -0
- requirements.txt +0 -0
- sever.py +68 -0
CNN_TEA_MODEL.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d6b5eef6d972efa8aa417dfc8f20873683c58e0189a9e35aac3121628aa13d49
|
3 |
+
size 378166960
|
Dockerfile
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10.11
|
2 |
+
WORKDIR /code
|
3 |
+
|
4 |
+
COPY ./requirements.txt /code/requirements.txt
|
5 |
+
|
6 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
7 |
+
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "sever:app"]
|
requirements.txt
ADDED
Binary file (5.83 kB). View file
|
|
sever.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
import os
|
8 |
+
import base64
|
9 |
+
from flask_cors import CORS
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
app = Flask(__name__)
|
14 |
+
CORS(app)
|
15 |
+
|
16 |
+
#dataset clasess
|
17 |
+
class_name = {
|
18 |
+
0: 'Blister Blight',
|
19 |
+
1: 'Brown Blight',
|
20 |
+
2: 'Gray Blight',
|
21 |
+
3: 'Healthy',
|
22 |
+
4: 'White Spot'
|
23 |
+
}
|
24 |
+
|
25 |
+
#load saved model
|
26 |
+
model_dir = './CNN_TEA_MODEL.h5'
|
27 |
+
model = load_model(model_dir)
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
@app.route("/predict", methods=["POST"])
|
34 |
+
def predictTest():
|
35 |
+
|
36 |
+
if 'file' not in request.files:
|
37 |
+
return jsonify({'error': 'No file part'}), 400
|
38 |
+
file = request.files['file']
|
39 |
+
if file.filename == '':
|
40 |
+
return jsonify({'error': 'No selected file'}), 400
|
41 |
+
if file:
|
42 |
+
# Convert the file storage to PIL Image and ensure it's in RGB
|
43 |
+
img = Image.open(io.BytesIO(file.read())).convert('RGB') # Added .convert('RGB')
|
44 |
+
img = img.resize((256, 256))
|
45 |
+
img_array = np.array(img)
|
46 |
+
img_array = np.expand_dims(img_array, axis=0)
|
47 |
+
img_array = img_array / 255.0 # Normalize
|
48 |
+
|
49 |
+
predictions = model.predict(img_array)
|
50 |
+
#get the class with the highest probability
|
51 |
+
predicted_class = np.argmax(predictions, axis=1)
|
52 |
+
predicted_class_name = class_name[predicted_class[0]]
|
53 |
+
|
54 |
+
result = {"class": predicted_class_name}
|
55 |
+
print("Prediction: ", result)
|
56 |
+
print(predictions)
|
57 |
+
|
58 |
+
return jsonify({'prediction': result})
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
app.run(debug=True)
|
67 |
+
|
68 |
+
|