willco-afk
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing import image
|
5 |
+
import numpy as np
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
# Load the pre-trained model
|
9 |
+
model = load_model('your_trained_model_resnet50.keras')
|
10 |
+
|
11 |
+
# Streamlit app title
|
12 |
+
st.title("Tree Decoration Prediction")
|
13 |
+
|
14 |
+
# Upload image for prediction
|
15 |
+
uploaded_file = st.file_uploader("Choose a tree image", type=["jpg", "jpeg", "png"])
|
16 |
+
|
17 |
+
if uploaded_file is not None:
|
18 |
+
# Display uploaded image
|
19 |
+
img = Image.open(uploaded_file)
|
20 |
+
st.image(img, caption="Uploaded Image", use_column_width=True)
|
21 |
+
|
22 |
+
# Prepare the image for prediction
|
23 |
+
img = img.resize((224, 224)) # Resizing image for ResNet50 input size
|
24 |
+
img_array = np.array(img) / 255.0 # Normalize
|
25 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
26 |
+
|
27 |
+
# Predict the class
|
28 |
+
prediction = model.predict(img_array)
|
29 |
+
|
30 |
+
# Show the prediction result
|
31 |
+
if prediction[0] > 0.5:
|
32 |
+
st.write("The tree is decorated!")
|
33 |
+
else:
|
34 |
+
st.write("The tree is undecorated!")
|