File size: 1,076 Bytes
f13f7ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import streamlit as st
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np
from PIL import Image

# Load the pre-trained model
model = load_model('your_trained_model_resnet50.keras')

# Streamlit app title
st.title("Tree Decoration Prediction")

# Upload image for prediction
uploaded_file = st.file_uploader("Choose a tree image", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Display uploaded image
    img = Image.open(uploaded_file)
    st.image(img, caption="Uploaded Image", use_column_width=True)

    # Prepare the image for prediction
    img = img.resize((224, 224))  # Resizing image for ResNet50 input size
    img_array = np.array(img) / 255.0  # Normalize
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension

    # Predict the class
    prediction = model.predict(img_array)

    # Show the prediction result
    if prediction[0] > 0.5:
        st.write("The tree is decorated!")
    else:
        st.write("The tree is undecorated!")