Manikanta-7013 commited on
Commit
9b0dadd
·
verified ·
1 Parent(s): 6d79377

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import tensorflow as tf
3
- from tensorflow.keras.preprocessing.image import ImageDataGenerator
4
- from tensorflow.keras.preprocessing import image
5
  import numpy as np
6
 
7
  # Check TensorFlow version
@@ -29,14 +28,14 @@ if uploaded_file is not None:
29
  cnn.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
30
 
31
  # Preprocess the uploaded image
32
- img = image.load_img(uploaded_file, target_size=(64, 64))
33
- img_array = image.img_to_array(img)
34
- img_array = np.expand_dims(img_array, axis=0)
35
- img_array /= 255.0 # Normalize the image data
36
 
37
  # Make prediction
38
  prediction = cnn.predict(img_array)
39
  if prediction[0][0] > 0.5:
40
- st.write("Prediction: Cat")
41
- else:
42
  st.write("Prediction: Dog")
 
 
 
1
  import streamlit as st
2
  import tensorflow as tf
3
+ from tensorflow.keras.preprocessing.image import img_to_array, load_img
 
4
  import numpy as np
5
 
6
  # Check TensorFlow version
 
28
  cnn.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
29
 
30
  # Preprocess the uploaded image
31
+ img = load_img(uploaded_file, target_size=(64, 64))
32
+ img_array = img_to_array(img)
33
+ img_array = img_array.reshape((1, img_array.shape[0], img_array.shape[1], img_array.shape[2]))
34
+ img_array = img_array / 255.0 # Normalize pixel values to [0, 1]
35
 
36
  # Make prediction
37
  prediction = cnn.predict(img_array)
38
  if prediction[0][0] > 0.5:
 
 
39
  st.write("Prediction: Dog")
40
+ else:
41
+ st.write("Prediction: Cat")