Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,20 @@ import streamlit as st
|
|
2 |
import tensorflow as tf
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
-
import tempfile
|
6 |
import zipfile
|
7 |
import os
|
8 |
|
9 |
-
|
|
|
10 |
def load_model_from_zip(zip_file_path):
|
11 |
-
with
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Load the model (assuming your model is 'your_trained_model.keras' inside the zip)
|
16 |
-
model_path = os.path.join(temp_dir, 'your_trained_model.keras')
|
17 |
-
model = tf.keras.models.load_model(model_path)
|
18 |
return model
|
19 |
|
20 |
-
# Load the model
|
21 |
-
model = load_model_from_zip('
|
22 |
|
23 |
# Streamlit UI
|
24 |
st.title("Christmas Tree Classifier")
|
@@ -40,7 +37,7 @@ if uploaded_file is not None:
|
|
40 |
prediction = model.predict(image_array)
|
41 |
|
42 |
# Interpret prediction (assuming binary classification)
|
43 |
-
class_names = ['Undecorated', 'Decorated']
|
44 |
predicted_class_index = 1 if prediction[0][0] >= 0.5 else 0 # Adjust threshold if needed
|
45 |
predicted_class = class_names[predicted_class_index]
|
46 |
|
|
|
2 |
import tensorflow as tf
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
|
|
5 |
import zipfile
|
6 |
import os
|
7 |
|
8 |
+
|
9 |
+
# Function to load the model from the zip file
|
10 |
def load_model_from_zip(zip_file_path):
|
11 |
+
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
12 |
+
zip_ref.extractall('.') # Extract to the current directory
|
13 |
+
# Load the SavedModel (no need for model_path anymore)
|
14 |
+
model = tf.keras.models.load_model('your_trained_model') # Replace 'your_trained_model' with your model folder name, if any
|
|
|
|
|
|
|
15 |
return model
|
16 |
|
17 |
+
# Load the model
|
18 |
+
model = load_model_from_zip('my_christmas_tree_model.zip') # Update with your actual zip file name
|
19 |
|
20 |
# Streamlit UI
|
21 |
st.title("Christmas Tree Classifier")
|
|
|
37 |
prediction = model.predict(image_array)
|
38 |
|
39 |
# Interpret prediction (assuming binary classification)
|
40 |
+
class_names = ['Undecorated', 'Decorated'] # Update with your actual class names
|
41 |
predicted_class_index = 1 if prediction[0][0] >= 0.5 else 0 # Adjust threshold if needed
|
42 |
predicted_class = class_names[predicted_class_index]
|
43 |
|