Spaces:
Sleeping
Sleeping
Merge pull request #2 from sdsc-ordes/fix-classifier-with-image-preprocessing
Browse files- README.md +1 -0
- call_models/entry_and_hotdog.py +5 -1
- call_models/input_handling.py +8 -1
- call_models/requirements.txt +25 -12
- requirements.txt → deprecate-requirements.txt +0 -0
README.md
CHANGED
|
@@ -5,6 +5,7 @@ colorFrom: yellow
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.39.0
|
|
|
|
| 8 |
app_file: call_models/entry_and_hotdog.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.39.0
|
| 8 |
+
python_version: 3.10
|
| 9 |
app_file: call_models/entry_and_hotdog.py
|
| 10 |
pinned: false
|
| 11 |
license: apache-2.0
|
call_models/entry_and_hotdog.py
CHANGED
|
@@ -25,6 +25,8 @@ from transformers import AutoModelForImageClassification
|
|
| 25 |
|
| 26 |
# setup for the ML model on huggingface (our wrapper)
|
| 27 |
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
|
|
|
|
|
|
| 28 |
# and the dataset of observations (hf dataset in our space)
|
| 29 |
dataset_id = "Saving-Willy/Happywhale-kaggle"
|
| 30 |
data_files = "data/train-00000-of-00001.parquet"
|
|
@@ -106,6 +108,7 @@ def push_observation(tab_log=None):
|
|
| 106 |
if __name__ == "__main__":
|
| 107 |
|
| 108 |
g_logger.info("App started.")
|
|
|
|
| 109 |
|
| 110 |
#g_logger.debug("debug message")
|
| 111 |
#g_logger.info("info message")
|
|
@@ -220,7 +223,8 @@ if __name__ == "__main__":
|
|
| 220 |
if tab_inference.button("Identify with cetacean classifier"):
|
| 221 |
#pipe = pipeline("image-classification", model="Saving-Willy/cetacean-classifier", trust_remote_code=True)
|
| 222 |
cetacean_classifier = AutoModelForImageClassification.from_pretrained("Saving-Willy/cetacean-classifier",
|
| 223 |
-
revision=
|
|
|
|
| 224 |
|
| 225 |
if st.session_state.image is None:
|
| 226 |
# TODO: cleaner design to disable the button until data input done?
|
|
|
|
| 25 |
|
| 26 |
# setup for the ML model on huggingface (our wrapper)
|
| 27 |
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
| 28 |
+
#classifier_revision = '0f9c15e2db4d64e7f622ade518854b488d8d35e6'
|
| 29 |
+
classifier_revision = 'main' # default/latest version
|
| 30 |
# and the dataset of observations (hf dataset in our space)
|
| 31 |
dataset_id = "Saving-Willy/Happywhale-kaggle"
|
| 32 |
data_files = "data/train-00000-of-00001.parquet"
|
|
|
|
| 108 |
if __name__ == "__main__":
|
| 109 |
|
| 110 |
g_logger.info("App started.")
|
| 111 |
+
g_logger.warning(f"[D] Streamlit version: {st.__version__}. Python version: {os.sys.version}")
|
| 112 |
|
| 113 |
#g_logger.debug("debug message")
|
| 114 |
#g_logger.info("info message")
|
|
|
|
| 223 |
if tab_inference.button("Identify with cetacean classifier"):
|
| 224 |
#pipe = pipeline("image-classification", model="Saving-Willy/cetacean-classifier", trust_remote_code=True)
|
| 225 |
cetacean_classifier = AutoModelForImageClassification.from_pretrained("Saving-Willy/cetacean-classifier",
|
| 226 |
+
revision=classifier_revision,
|
| 227 |
+
trust_remote_code=True)
|
| 228 |
|
| 229 |
if st.session_state.image is None:
|
| 230 |
# TODO: cleaner design to disable the button until data input done?
|
call_models/input_handling.py
CHANGED
|
@@ -6,6 +6,8 @@ import hashlib
|
|
| 6 |
import logging
|
| 7 |
|
| 8 |
import streamlit as st
|
|
|
|
|
|
|
| 9 |
|
| 10 |
m_logger = logging.getLogger(__name__)
|
| 11 |
# we can set the log level locally for funcs in this module
|
|
@@ -135,7 +137,12 @@ def setup_input(viewcontainer: st.delta_generator.DeltaGenerator=None, _allowed_
|
|
| 135 |
|
| 136 |
if uploaded_filename is not None:
|
| 137 |
# Display the uploaded image
|
| 138 |
-
image = Image.open(uploaded_filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
viewcontainer.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 140 |
# store the image in the session state
|
| 141 |
st.session_state.image = image
|
|
|
|
| 6 |
import logging
|
| 7 |
|
| 8 |
import streamlit as st
|
| 9 |
+
import cv2
|
| 10 |
+
import numpy as np
|
| 11 |
|
| 12 |
m_logger = logging.getLogger(__name__)
|
| 13 |
# we can set the log level locally for funcs in this module
|
|
|
|
| 137 |
|
| 138 |
if uploaded_filename is not None:
|
| 139 |
# Display the uploaded image
|
| 140 |
+
#image = Image.open(uploaded_filename)
|
| 141 |
+
# load image using cv2 format, so it is compatible with the ML models
|
| 142 |
+
file_bytes = np.asarray(bytearray(uploaded_filename.read()), dtype=np.uint8)
|
| 143 |
+
image = cv2.imdecode(file_bytes, 1)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
viewcontainer.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 147 |
# store the image in the session state
|
| 148 |
st.session_state.image = image
|
call_models/requirements.txt
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
huggingface_hub
|
| 4 |
-
torch
|
| 5 |
|
| 6 |
-
pandas
|
| 7 |
-
numpy
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
folium
|
| 13 |
streamlit_folium
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 1 |
+
numpy==1.24
|
| 2 |
+
pandas==2.2.3
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# frontend
|
| 6 |
+
streamlit==1.39.0
|
| 7 |
+
## for nice map tiles
|
| 8 |
folium
|
| 9 |
streamlit_folium
|
| 10 |
+
folium==0.18.0
|
| 11 |
+
streamlit_folium==0.23.1
|
| 12 |
+
|
| 13 |
+
# backend
|
| 14 |
+
datasets==3.0.2
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# running ML models
|
| 18 |
+
|
| 19 |
+
## to use ML models hosted on HF
|
| 20 |
+
huggingface-hub==0.26.1
|
| 21 |
+
transformers==4.46.0
|
| 22 |
+
#torch
|
| 23 |
+
## +minimal reqs for locally running model - with PIL load
|
| 24 |
+
pytorch-lightning<=1.5.10
|
| 25 |
+
timm==0.5.4
|
| 26 |
+
pillow==10.4.0
|
| 27 |
|
| 28 |
+
## also need opencv for handling images in the later model with preprocessing
|
| 29 |
+
opencv-python-headless==4.5.5.64
|
| 30 |
+
albumentations==1.1.0
|
requirements.txt → deprecate-requirements.txt
RENAMED
|
File without changes
|