willco-afk commited on
Commit
43f37ad
·
verified ·
1 Parent(s): bf49947

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -36
app.py CHANGED
@@ -1,41 +1,15 @@
 
1
  import os
2
-
3
- # Set the environment variable before importing tensorflow
4
- os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
5
-
6
- import streamlit as st
7
  import tensorflow as tf
8
- from tensorflow.keras.models import load_model
9
- from tensorflow.keras.preprocessing import image
10
- import numpy as np
11
- from PIL import Image
12
-
13
- # Load the trained model
14
- model = load_model('your_trained_model_resnet50.keras')
15
 
16
- # Streamlit UI for uploading an image
17
- st.title("Tree Decoration Prediction Model")
 
18
 
19
- # Upload an image
20
- uploaded_file = st.file_uploader("Choose a tree image...", type="jpg")
 
 
21
 
22
- if uploaded_file is not None:
23
- # Open the image file
24
- img = Image.open(uploaded_file)
25
-
26
- # Preprocess the image for ResNet50 (resize, scale, etc.)
27
- img = img.resize((224, 224)) # Resize to ResNet50 input size
28
- img_array = np.array(img) / 255.0 # Normalize pixel values to [0, 1]
29
- img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
30
-
31
- # Predict if the tree is decorated or undecorated
32
- prediction = model.predict(img_array)
33
-
34
- # Display the prediction result
35
- if prediction[0] > 0.5:
36
- st.write("The tree is decorated!")
37
- else:
38
- st.write("The tree is undecorated.")
39
-
40
- # Display the uploaded image
41
- st.image(img, caption="Uploaded Image.", use_column_width=True)
 
1
+ import zipfile
2
  import os
 
 
 
 
 
3
  import tensorflow as tf
 
 
 
 
 
 
 
4
 
5
+ # Path to the zipped model file in Hugging Face
6
+ zip_model_path = '/app/your_trained_model.keras.zip'
7
+ unzipped_model_path = '/app/your_trained_model.keras'
8
 
9
+ # Unzip the model file if not already unzipped
10
+ if not os.path.exists(unzipped_model_path):
11
+ with zipfile.ZipFile(zip_model_path, 'r') as zip_ref:
12
+ zip_ref.extractall('/app')
13
 
14
+ # Load the model
15
+ model = tf.keras.models.load_model(unzipped_model_path)