import streamlit as st import pickle import pandas as pd import numpy as np from PIL import Image with open('model.pkl', 'rb') as model: model = pickle.load(model) def run(): #Title st.title('🔍 Forest Fire & Smoke Prediction') images_by_class = { "": [ "fire/fire1.jpg", "non-fire/non-fire1.png", "smoke/smoke4.png" ] } # Display in grid for cls, image_paths in images_by_class.items(): st.subheader(cls.capitalize()) cols = st.columns(len(image_paths)) for i, path in enumerate(image_paths): img = Image.open(path) with cols[i]: st.image(img, use_container_width=True) # Upload image uploaded_file = st.file_uploader( "Upload your own image", type=["jpg", "jpeg", "png"], label_visibility="visible" ) # Upload file if uploaded_file is not None: # Show image img = Image.open(uploaded_file).convert('RGB') st.image(img, caption="Uploaded Image", use_container_width=True) # Preprocess img_resized = img.resize((150, 150)) img_array = np.expand_dims(np.array(img_resized) / 255.0, axis=0) # Load model model = tf.keras.models.load_model("best_model.h5") class_names = ["fire", "non-fire", "smoke"] # # Predict # prediction = model.predict(img_array) # predicted_label = class_names[np.argmax(prediction)] # confidence = np.max(prediction) # # Show Prediction # st.success(f"✅ Prediction: **{predicted_label}**") # st.write(f"Confidence: **{confidence:.2%}**") if __name__ == '__main__': run()