willco-afk commited on
Commit
8bf06b4
·
verified ·
1 Parent(s): 13a2a47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,6 +1,12 @@
 
 
 
 
 
1
  import tensorflow as tf
2
  import streamlit as st
3
- import os
 
4
 
5
  # Load the model
6
  model = tf.keras.models.load_model('your_model.keras')
@@ -10,7 +16,19 @@ st.title('Tree Decoration Prediction')
10
 
11
  # Example usage in your Streamlit app
12
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png"])
 
13
  if uploaded_image:
14
- st.image(uploaded_image, caption="Uploaded Image.", use_column_width=True)
15
- prediction = model.predict(uploaded_image)
16
- st.write(f"Prediction: {prediction}")
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ # Set the environment variable to use the pure-Python implementation of protobuf
3
+ os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
4
+
5
+ # Now import TensorFlow
6
  import tensorflow as tf
7
  import streamlit as st
8
+ from PIL import Image
9
+ import numpy as np
10
 
11
  # Load the model
12
  model = tf.keras.models.load_model('your_model.keras')
 
16
 
17
  # Example usage in your Streamlit app
18
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png"])
19
+
20
  if uploaded_image:
21
+ # Open and display the image
22
+ img = Image.open(uploaded_image)
23
+ st.image(img, caption="Uploaded Image.", use_column_width=True)
24
+
25
+ # Preprocess the image to match model input
26
+ img = img.resize((224, 224)) # Resize if necessary to match your model input size
27
+ img_array = np.array(img) / 255.0 # Normalize the image (if necessary)
28
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
29
+
30
+ # Get the prediction
31
+ prediction = model.predict(img_array)
32
+
33
+ # Show prediction result
34
+ st.write(f"Prediction: {prediction[0][0]}") # Adjust according to your model's output format