willco-afk commited on
Commit
c7589e5
·
verified ·
1 Parent(s): ea2e2e2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 model
9
+ model = load_model('your_trained_model_resnet50.keras')
10
+
11
+ # Streamlit title
12
+ st.title("Tree Decoration Prediction Model")
13
+
14
+ # Upload an image
15
+ uploaded_file = st.file_uploader("Choose a tree image...", type="jpg")
16
+
17
+ if uploaded_file is not None:
18
+ # Open the image file
19
+ img = Image.open(uploaded_file)
20
+
21
+ # Preprocess the image for ResNet50 (resize, scale, etc.)
22
+ img = img.resize((224, 224))
23
+ img_array = np.array(img) / 255.0 # Normalize
24
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
25
+
26
+ # Make a prediction
27
+ prediction = model.predict(img_array)
28
+
29
+ # Display prediction result
30
+ if prediction[0] > 0.5:
31
+ st.write("The tree is decorated!")
32
+ else:
33
+ st.write("The tree is undecorated.")
34
+
35
+ # Display the image
36
+ st.image(img, caption="Uploaded Image.", use_column_width=True)