Suhani-2407/Fire-Detection
0
1from flask import Flask, request, jsonify2import tensorflow as tf3import numpy as np4from tensorflow.keras.preprocessing import image5 6app = Flask(__name__)7model = tf.keras.models.load_model("MobileNet_Fire.h5")8 9class_labels = {0: "Fake", 1: "Low", 2: "Medium", 3: "High"} # Update as per your training10 11@app.route("/predict", methods=["POST"])12def 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.016 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 24if __name__ == "__main__":25 app.run(debug=True)26 