Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,49 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
# app = Flask(__name__)
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
import streamlit as st
|
50 |
from tensorflow.keras.models import load_model
|
|
|
1 |
+
from flask import Flask, request, jsonify, render_template
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
from efficientnet.tfkeras import preprocess_input
|
5 |
+
import numpy as np
|
|
|
|
|
6 |
|
7 |
+
app = Flask(__name__)
|
8 |
+
model = load_model('EfficientNet_ModelWeights.keras')
|
9 |
|
10 |
+
def preprocess_and_predict(model, img_path, target_size=(224, 224)):
|
11 |
+
#Load and preprocess the image
|
12 |
+
img = image.load_img(img_path, target_size=target_size)
|
13 |
+
img_array = image.img_to_array(img)
|
14 |
+
img_array = np.expand_dims(img_array, axis=0)
|
15 |
+
img_array = preprocess_input(img_array)
|
16 |
|
17 |
+
# Make prediction
|
18 |
+
prediction = model.predict(img_array)
|
19 |
+
predicted_class = np.argmax(prediction)
|
20 |
|
21 |
+
# Return the predicted class
|
22 |
+
return predicted_class
|
23 |
|
24 |
+
@app.route('/')
|
25 |
+
def home():
|
26 |
+
return render_template('index.html')
|
27 |
|
28 |
+
@app.route('/predict', methods=['POST'])
|
29 |
+
def predict():
|
30 |
+
if 'file' not in request.files:
|
31 |
+
return jsonify({'error': 'No file part'})
|
32 |
|
33 |
+
file = request.files['file']
|
34 |
|
35 |
+
# Save the uploaded file temporarily
|
36 |
+
file_path = 'temp_image.jpg'
|
37 |
+
file.save(file_path)
|
38 |
|
39 |
+
# Make prediction
|
40 |
+
predicted_class = preprocess_and_predict(model, file_path)
|
41 |
|
42 |
+
# Return the predicted class as a response
|
43 |
+
return render_template('index.html', prediction=predicted_class)
|
44 |
|
45 |
+
if __name__ == '__main__':
|
46 |
+
app.run(debug=True)
|
47 |
|
48 |
import streamlit as st
|
49 |
from tensorflow.keras.models import load_model
|