Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +12 -10
src/streamlit_app.py
CHANGED
|
@@ -6,12 +6,6 @@ import os
|
|
| 6 |
import platform
|
| 7 |
from tensorflow.keras.preprocessing.image import img_to_array
|
| 8 |
|
| 9 |
-
# Safely get the directory of the current script (works locally and on hosted platforms)
|
| 10 |
-
try:
|
| 11 |
-
current_dir = os.path.dirname(__file__)
|
| 12 |
-
except NameError:
|
| 13 |
-
current_dir = os.getcwd()
|
| 14 |
-
|
| 15 |
# Constants
|
| 16 |
IMG_SIZE = 128
|
| 17 |
CLASS_NAMES = ['cardboard', 'glass', 'metal', 'paper', 'plastic']
|
|
@@ -25,11 +19,19 @@ ECO_TIPS = {
|
|
| 25 |
'plastic': "🧴 *Tip:* Not all plastics are recyclable. Check the plastic code and always clean before disposal."
|
| 26 |
}
|
| 27 |
|
| 28 |
-
# Dynamically set model path for local vs Hugging Face
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
MODEL_PATH = os.path.abspath(os.path.join(current_dir, "src", "notebook", "models", "trashsort_cnn.h5"))
|
| 31 |
-
else: # Local
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
@st.cache_resource(show_spinner=False)
|
| 35 |
def load_model():
|
|
|
|
| 6 |
import platform
|
| 7 |
from tensorflow.keras.preprocessing.image import img_to_array
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Constants
|
| 10 |
IMG_SIZE = 128
|
| 11 |
CLASS_NAMES = ['cardboard', 'glass', 'metal', 'paper', 'plastic']
|
|
|
|
| 19 |
'plastic': "🧴 *Tip:* Not all plastics are recyclable. Check the plastic code and always clean before disposal."
|
| 20 |
}
|
| 21 |
|
| 22 |
+
# Dynamically set model path for local vs Hugging Face Spaces
|
| 23 |
+
try:
|
| 24 |
+
current_dir = os.path.dirname(__file__)
|
| 25 |
+
except NameError:
|
| 26 |
+
current_dir = os.getcwd()
|
| 27 |
+
|
| 28 |
+
if "SPACE_ID" in os.environ: # Running on Hugging Face Spaces
|
| 29 |
MODEL_PATH = os.path.abspath(os.path.join(current_dir, "src", "notebook", "models", "trashsort_cnn.h5"))
|
| 30 |
+
else: # Local environment
|
| 31 |
+
if platform.system() == "Windows":
|
| 32 |
+
MODEL_PATH = r"C:\Users\Cherilyn\Desktop\trash_sort\src\models\trashsort_cnn.h5"
|
| 33 |
+
else:
|
| 34 |
+
MODEL_PATH = os.path.abspath(os.path.join(current_dir, "src", "models", "trashsort_cnn.h5"))
|
| 35 |
|
| 36 |
@st.cache_resource(show_spinner=False)
|
| 37 |
def load_model():
|