ajoy0071998 commited on
Commit
6d2ceaa
·
verified ·
1 Parent(s): b1f0b31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py CHANGED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
5
+ from PIL import Image
6
+ import json
7
+
8
+ # Load the model
9
+ model = tf.keras.models.load_model("satellite_image_model.h5")
10
+
11
+ # Load class labels
12
+ with open("label_map.json", "r") as f:
13
+ class_labels = json.load(f)
14
+
15
+ # Reverse the class labels to get index to class name mapping
16
+ class_labels = {v: k for k, v in class_labels.items()}
17
+
18
+ # Function to preprocess the image
19
+ def preprocess_image(image, target_size=(224, 224)):
20
+ image = image.resize(target_size)
21
+ image = img_to_array(image)
22
+ image = np.expand_dims(image, axis=0)
23
+ image = image / 255.0 # Normalizing
24
+ return image
25
+
26
+ # Streamlit App
27
+ st.title("Satellite Image Classification")
28
+
29
+ st.write("Upload a satellite image, and the model will predict its class.")
30
+
31
+ # Image uploader
32
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
33
+
34
+ if uploaded_file is not None:
35
+ # Display the uploaded image
36
+ image = Image.open(uploaded_file)
37
+ st.image(image, caption="Uploaded Image", use_column_width=True)
38
+
39
+ # Preprocess the image
40
+ processed_image = preprocess_image(image)
41
+
42
+ # Make prediction
43
+ predictions = model.predict(processed_image)
44
+ class_idx = np.argmax(predictions, axis=1)[0]
45
+ predicted_class = class_labels[class_idx]
46
+
47
+ # Show the predicted class
48
+ st.write(f"Predicted Class: {predicted_class}")