notbeekay commited on
Commit
629aff5
·
verified ·
1 Parent(s): 7a1aa0e

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +53 -0
  3. best_model.keras +3 -0
  4. requirements.txt +10 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ best_model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ import cv2
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # Load the model
8
+ model = load_model('best_model.keras')
9
+
10
+ def preprocess_image(image):
11
+ # Resize the image as required by the model
12
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
13
+ img = cv2.resize(img, (220, 220)) # Resize to match the model input
14
+ # Normalize the image
15
+ img = img.astype('float32') / 255.0
16
+ # Add a batch dimension
17
+ img = np.expand_dims(img, axis=0)
18
+ return img
19
+
20
+ def run():
21
+ # Create title
22
+ st.title('Detecting Fire in Forest Images')
23
+
24
+ # Create a form for image input
25
+ with st.form('form_forest_fire_detection'):
26
+ # Image upload
27
+ uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
28
+
29
+ # Submit button
30
+ submitted = st.form_submit_button('Detect Fire or No Fire')
31
+
32
+ if uploaded_image:
33
+ # Display the uploaded image
34
+ st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)
35
+
36
+ if submitted:
37
+ # Preprocess the image
38
+ image = Image.open(uploaded_image)
39
+ preprocessed_image = preprocess_image(image)
40
+
41
+ # Predict using the model
42
+ prediction = model.predict(preprocessed_image)
43
+
44
+ # For example, if prediction > 0.5 classify as 'No Fire', otherwise 'Fire'
45
+ fire_probability = prediction[0][0]
46
+ result = 'No Fire' if fire_probability > 0.5 else 'Fire'
47
+
48
+ st.write('## Prediction: ', result)
49
+ st.write('## Raw Prediction Output: ', prediction)
50
+
51
+
52
+ if __name__ == '__main__':
53
+ run()
best_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:587506ed2de9f937aab1fd196f0d644df71cb5106dbc643b875441a88bbf112f
3
+ size 494759003
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ opencv-python
3
+ seaborn
4
+ matplotlib
5
+ Pillow
6
+ tensorflow
7
+ numpy
8
+ pandas
9
+ scikit-learn
10
+ datasets