StefVero commited on
Commit
918ca03
·
verified ·
1 Parent(s): 4eeebf4

Upload 8 files

Browse files
Files changed (2) hide show
  1. src/intel_classifier_v2.h5 +3 -0
  2. src/streamlit_app.py +7 -16
src/intel_classifier_v2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ea564db71ecc2810f6223e3abcb752ca39fb578ec93ca3b1c2247f99684cc45
3
+ size 132216680
src/streamlit_app.py CHANGED
@@ -3,26 +3,19 @@ import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
5
  import json
6
- import os
7
 
8
- # Get the directory where streamlit_app.py is located
9
- BASE_DIR = os.path.dirname(os.path.abspath(__file__))
 
 
 
10
 
11
- # Build the paths dynamically
12
- model_path = os.path.join(BASE_DIR, "intel_classifier_improved.keras")
13
- json_path = os.path.join(BASE_DIR, "class_indices.json")
14
-
15
- st.write(f"Looking for model at: {model_path}")
16
-
17
- model = tf.keras.models.load_model(model_path)
18
- with open(json_path, "r") as f:
19
- class_indices = json.load(f)
20
 
21
  # Load class indices
22
  with open("./src/class_indices.json", "r") as f:
23
  class_indices = json.load(f)
24
 
25
- # Convert to index → class mapping
26
  class_names = list(class_indices.keys())
27
 
28
 
@@ -31,7 +24,7 @@ def run():
31
 
32
  st.title("Environment Image Classifier")
33
 
34
- # Form input (consistent with your style)
35
  with st.form(key='form_image_classifier'):
36
  uploaded_file = st.file_uploader(
37
  "Upload an image",
@@ -72,7 +65,5 @@ def run():
72
  for i, prob in enumerate(prediction):
73
  st.write(f"{class_names[i]}: {prob:.2%}")
74
 
75
-
76
- # Run app
77
  if __name__ == '__main__':
78
  run()
 
3
  import numpy as np
4
  from PIL import Image
5
  import json
 
6
 
7
+ # Load model
8
+ @st.cache_resource
9
+ def load_model():
10
+ model = tf.keras.models.load_model("./src/intel_classifier_improved.h5")
11
+ return model
12
 
13
+ model = load_model()
 
 
 
 
 
 
 
 
14
 
15
  # Load class indices
16
  with open("./src/class_indices.json", "r") as f:
17
  class_indices = json.load(f)
18
 
 
19
  class_names = list(class_indices.keys())
20
 
21
 
 
24
 
25
  st.title("Environment Image Classifier")
26
 
27
+ # Form input
28
  with st.form(key='form_image_classifier'):
29
  uploaded_file = st.file_uploader(
30
  "Upload an image",
 
65
  for i, prob in enumerate(prediction):
66
  st.write(f"{class_names[i]}: {prob:.2%}")
67
 
 
 
68
  if __name__ == '__main__':
69
  run()