willco-afk commited on
Commit
ff6e3b9
·
verified ·
1 Parent(s): 400ac6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
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
- # Function to load model from a zip file
 
10
  def load_model_from_zip(zip_file_path):
11
- with tempfile.TemporaryDirectory() as temp_dir:
12
- with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
13
- zip_ref.extractall(temp_dir)
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 from the zip file
21
- model = load_model_from_zip('/content/drive/MyDrive/my_christmas_tree_model.zip') # Replace 'my_christmas_tree_model.zip' with the actual name of the zip file
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'] #Update your class names here
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