Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +62 -0
- class_names.pkl +3 -0
- ecosort.h5 +3 -0
- history_18.json +1 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, render_template, jsonify
|
2 |
+
from flask_cors import CORS
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
|
8 |
+
# Load the model
|
9 |
+
model = load_model('ecosort.h5')
|
10 |
+
|
11 |
+
# Define a dictionary to map class numbers to class names
|
12 |
+
class_mapping = {
|
13 |
+
0: 'battery',
|
14 |
+
1: 'biological',
|
15 |
+
2: 'brown-glass',
|
16 |
+
3: 'cardboard',
|
17 |
+
4: 'clothes',
|
18 |
+
5: 'green-glass',
|
19 |
+
6: 'metal',
|
20 |
+
7: 'paper',
|
21 |
+
8: 'plastic',
|
22 |
+
9: 'shoes',
|
23 |
+
10: 'trash',
|
24 |
+
11: 'white-glass'
|
25 |
+
}
|
26 |
+
|
27 |
+
app = Flask(__name__)
|
28 |
+
CORS(app)
|
29 |
+
|
30 |
+
@app.route('/')
|
31 |
+
def home():
|
32 |
+
return render_template('index.html')
|
33 |
+
|
34 |
+
@app.route('/predict', methods=['POST'])
|
35 |
+
def predict():
|
36 |
+
if 'file' not in request.files:
|
37 |
+
return "No file uploaded"
|
38 |
+
|
39 |
+
file = request.files['file']
|
40 |
+
if file.filename == '':
|
41 |
+
return "No selected file"
|
42 |
+
|
43 |
+
img = Image.open(io.BytesIO(file.read()))
|
44 |
+
if img is None:
|
45 |
+
return "Invalid image file"
|
46 |
+
|
47 |
+
# Preprocess the image
|
48 |
+
img = img.resize((224, 224))
|
49 |
+
img_array = np.asarray(img) / 255.0
|
50 |
+
|
51 |
+
# Make predictions using your model
|
52 |
+
prediction = model.predict(np.expand_dims(img_array, axis=0))
|
53 |
+
predicted_class = np.argmax(prediction)
|
54 |
+
|
55 |
+
# Get the class name from the dictionary
|
56 |
+
class_name = class_mapping.get(predicted_class, 'Unknown Class')
|
57 |
+
|
58 |
+
# Return the prediction result as JSON
|
59 |
+
return jsonify({'prediction': class_name})
|
60 |
+
|
61 |
+
if __name__ == '__main__':
|
62 |
+
app.run(debug=True)
|
class_names.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b0751909e26b183611f5b9d2dafe1c4ee7ef2497d82550ddbf533fd71079fb35
|
3 |
+
size 673
|
ecosort.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ddac300fa8ba0c0ad74142672b8af74f1489d7d83021cb3dfd1e133defbcd083
|
3 |
+
size 4878700
|
history_18.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"loss":{"0":1.5341056585,"1":1.2222961187,"2":1.1268401146,"3":1.0727485418,"4":1.0110989809,"5":0.9687610269,"6":0.9271946549,"7":0.9024689794,"8":0.8692187667,"9":0.8614675999,"10":0.8234134316,"11":0.7991991639,"12":0.7842864394,"13":0.7855607867,"14":0.7717342377,"15":0.7669754028,"16":0.7367596626,"17":0.7274986506,"18":0.7208561301,"19":0.7309293151,"20":0.6990557909,"21":0.6857045293,"22":0.6837792397,"23":0.6891143322,"24":0.6718835235,"25":0.6616758108,"26":0.6490302086,"27":0.6551122665,"28":0.6534580588,"29":0.6386965513,"30":0.6457798481,"31":0.6363674998,"32":0.6198709607,"33":0.6150842905,"34":0.6078572869},"accuracy":{"0":0.5067268014,"1":0.5992910862,"2":0.6270844936,"3":0.6481108665,"4":0.6675260067,"5":0.6796100736,"6":0.698702991,"7":0.7039394379,"8":0.7152178884,"9":0.7167485952,"10":0.7352775335,"11":0.7384194136,"12":0.7441391945,"13":0.7456698418,"14":0.7495367527,"15":0.7470393777,"16":0.7576733828,"17":0.764359951,"18":0.7679851651,"19":0.7696769238,"20":0.771368742,"21":0.777007997,"22":0.7773302197,"23":0.7737050056,"24":0.7787802815,"25":0.7829694748,"26":0.7897365689,"27":0.7880448103,"28":0.7878031135,"29":0.7944090962,"30":0.790381074,"31":0.7954563498,"32":0.8002900481,"33":0.8006122708,"34":0.8002900481},"val_loss":{"0":1.4085903168,"1":1.2477800846,"2":1.1582015753,"3":1.1763260365,"4":1.1366167068,"5":1.1295882463,"6":1.171626687,"7":1.2620954514,"8":1.0351012945,"9":0.9841659069,"10":1.0137987137,"11":1.0116152763,"12":0.9565749168,"13":1.0655890703,"14":0.9031764269,"15":0.9237803221,"16":0.9115158916,"17":0.9859743714,"18":0.8955271244,"19":0.9202463031,"20":0.9681856632,"21":0.9304918051,"22":0.9144411683,"23":0.8983772397,"24":0.9408393502,"25":0.9417611957,"26":0.8453836441,"27":0.8206394911,"28":0.8543355465,"29":0.8252739906,"30":0.9412660599,"31":0.8566061854,"32":0.7821202874,"33":0.8085387349,"34":0.8927829862},"val_accuracy":{"0":0.547711134,"1":0.5828498006,"2":0.631205678,"3":0.6382978559,"4":0.6579626203,"5":0.6573178768,"6":0.6421663165,"7":0.6295937896,"8":0.6898775101,"9":0.7034171224,"10":0.6992263198,"11":0.7043842673,"12":0.7240489721,"13":0.6882656217,"14":0.7250161171,"15":0.7246937752,"16":0.7337201834,"17":0.7153449655,"18":0.7446808219,"19":0.7253385186,"20":0.7166344523,"21":0.7330754399,"22":0.7456479669,"23":0.7491940856,"24":0.7221147418,"25":0.7311412096,"26":0.7585428953,"27":0.7549967766,"28":0.7537072897,"29":0.7633784413,"30":0.7324306965,"31":0.7530625463,"32":0.762411356,"33":0.7643455863,"34":0.7543520331}}
|