Akshay-Vs commited on
Commit
ad25c15
1 Parent(s): 245e395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -6,43 +6,36 @@ import numpy as np
6
 
7
  path_to_model = "nova.h5"
8
 
9
- # Load the trained model
10
  model = tf.keras.models.load_model(path_to_model)
11
 
12
- # Set the default height and width of the uploaded image
13
  IMG_HEIGHT = 180
14
  IMG_WIDTH = 180
15
 
16
- # Define a function to preprocess the image
17
- # Define a function to preprocess the image
18
  def preprocess_image(image):
19
- # Resize the image to the expected input size of the model
20
- img = image.resize((IMG_HEIGHT, IMG_WIDTH))
21
- # Reshape the image array to match the input shape of the model
22
- img_array = np.array(img).reshape((1, IMG_HEIGHT, IMG_WIDTH, 3))
23
- # Normalize the pixel values
24
  img_array = img_array / 255.0
 
25
  return img_array
26
 
27
 
 
28
  # Create the Streamlit app
29
  def main():
30
- # Set the title and a brief description
31
  st.title("Nova'23 Classification model")
32
- # Add an image upload option
33
  uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
34
 
35
- # If an image has been uploaded, display it and make a prediction
36
  if uploaded_image is not None:
37
- # Display the uploaded image
38
  image = Image.open(uploaded_image)
39
  st.image(image, caption='Uploaded Image', use_column_width=True)
40
 
41
- # Preprocess the image for the model
42
- input_image = preprocess_image(image)
43
-
44
- # Make a prediction using the model
45
- prediction = model.predict(input_image)
46
 
47
  # Display the prediction
48
  if prediction[0][0] > prediction[0][1]:
 
6
 
7
  path_to_model = "nova.h5"
8
 
 
9
  model = tf.keras.models.load_model(path_to_model)
10
 
11
+ #default height and width of the uploaded image
12
  IMG_HEIGHT = 180
13
  IMG_WIDTH = 180
14
 
15
+ # Preprocessing
 
16
  def preprocess_image(image):
17
+ if image.size != (IMG_HEIGHT, IMG_WIDTH):
18
+ image = image.resize((IMG_HEIGHT, IMG_WIDTH))
19
+
20
+ img_array = img_to_array(image)
 
21
  img_array = img_array / 255.0
22
+ img_array = np.reshape(img_array, (1, IMG_HEIGHT, IMG_WIDTH, 3))
23
  return img_array
24
 
25
 
26
+
27
  # Create the Streamlit app
28
  def main():
 
29
  st.title("Nova'23 Classification model")
 
30
  uploaded_image = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
31
 
32
+ # Display the image
33
  if uploaded_image is not None:
 
34
  image = Image.open(uploaded_image)
35
  st.image(image, caption='Uploaded Image', use_column_width=True)
36
 
37
+ input_image = preprocess_image(image) #preprocessing
38
+ prediction = model.predict(input_image) #predicting
 
 
 
39
 
40
  # Display the prediction
41
  if prediction[0][0] > prediction[0][1]: