Suhani-2407 commited on
Commit
df81665
·
verified ·
1 Parent(s): c9ff5bf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from tensorflow.keras.preprocessing import image
5
+
6
+ app = Flask(__name__)
7
+ model = tf.keras.models.load_model("MobileNet_Fire.h5")
8
+
9
+ class_labels = {0: "Fake", 1: "Low", 2: "Medium", 3: "High"} # Update as per your training
10
+
11
+ @app.route("/predict", methods=["POST"])
12
+ def predict():
13
+ file = request.files["file"]
14
+ img = image.load_img(file, target_size=(128, 128))
15
+ img_array = image.img_to_array(img) / 255.0
16
+ img_array = np.expand_dims(img_array, axis=0)
17
+
18
+ predictions = model.predict(img_array)
19
+ predicted_class = class_labels[np.argmax(predictions)]
20
+ confidence = float(np.max(predictions))
21
+
22
+ return jsonify({"prediction": predicted_class, "confidence": confidence})
23
+
24
+ if __name__ == "__main__":
25
+ app.run(debug=True)