Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,13 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
os.system("pip install tensorflow")
|
3 |
os.system("pip install scikit-learn")
|
4 |
|
5 |
-
import streamlit as st
|
6 |
import tensorflow as tf
|
7 |
import numpy as np
|
8 |
import pickle
|
@@ -16,8 +21,15 @@ EXPECTED_SIZE = (64, 64) # Update this based on your model's input shape
|
|
16 |
def load_resources():
|
17 |
"""Load model and label encoder."""
|
18 |
try:
|
19 |
-
# Try loading with
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
except Exception as e:
|
22 |
st.error(f"Error loading model: {str(e)}")
|
23 |
return None, None
|
@@ -63,7 +75,6 @@ def predict(image):
|
|
63 |
return f"Error during prediction: {str(e)}"
|
64 |
|
65 |
# Streamlit UI
|
66 |
-
st.set_page_config(page_title="Image Classifier", layout="wide")
|
67 |
st.markdown("""
|
68 |
<h1 style='text-align: center; color: #4A90E2;'>🖼️ Image Classification App</h1>
|
69 |
<p style='text-align: center; font-size: 18px;'>Upload an image and let our model classify it for you!</p>
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Must be the first Streamlit command
|
5 |
+
st.set_page_config(page_title="Image Classifier", layout="wide")
|
6 |
+
|
7 |
+
# Now import other libraries
|
8 |
os.system("pip install tensorflow")
|
9 |
os.system("pip install scikit-learn")
|
10 |
|
|
|
11 |
import tensorflow as tf
|
12 |
import numpy as np
|
13 |
import pickle
|
|
|
21 |
def load_resources():
|
22 |
"""Load model and label encoder."""
|
23 |
try:
|
24 |
+
# Try loading with custom InputLayer configuration
|
25 |
+
custom_objects = {
|
26 |
+
'InputLayer': lambda **kwargs: tf.keras.layers.InputLayer(**{k: v for k, v in kwargs.items() if k != 'batch_shape'})
|
27 |
+
}
|
28 |
+
model = tf.keras.models.load_model(
|
29 |
+
MODEL_PATH,
|
30 |
+
compile=False,
|
31 |
+
custom_objects=custom_objects
|
32 |
+
)
|
33 |
except Exception as e:
|
34 |
st.error(f"Error loading model: {str(e)}")
|
35 |
return None, None
|
|
|
75 |
return f"Error during prediction: {str(e)}"
|
76 |
|
77 |
# Streamlit UI
|
|
|
78 |
st.markdown("""
|
79 |
<h1 style='text-align: center; color: #4A90E2;'>🖼️ Image Classification App</h1>
|
80 |
<p style='text-align: center; font-size: 18px;'>Upload an image and let our model classify it for you!</p>
|