diff --git a/audio-to-text/Containerfile b/audio-to-text/Containerfile index c48dcc2..8719e66 100644 --- a/audio-to-text/Containerfile +++ b/audio-to-text/Containerfile @@ -1,4 +1,4 @@ -FROM registry.access.redhat.com/ubi9/python-311:1-66 +FROM registry.access.redhat.com/ubi9/python-311:1-66.1720018730 WORKDIR /locallm COPY requirements.txt /locallm/requirements.txt RUN pip install --upgrade pip && \ diff --git a/chatbot/Containerfile b/chatbot/Containerfile index 863fcd9..585f4e4 100644 --- a/chatbot/Containerfile +++ b/chatbot/Containerfile @@ -1,4 +1,4 @@ -FROM registry.access.redhat.com/ubi9/python-311:1-66 +FROM registry.access.redhat.com/ubi9/python-311:1-66.1720018730 WORKDIR /chat COPY requirements.txt . RUN pip install --upgrade pip diff --git a/codegen/Containerfile b/codegen/Containerfile index 70cd2e3..6a3258d 100644 --- a/codegen/Containerfile +++ b/codegen/Containerfile @@ -1,4 +1,4 @@ -FROM registry.access.redhat.com/ubi9/python-311:1-66 +FROM registry.access.redhat.com/ubi9/python-311:1-66.1720018730 WORKDIR /codegen COPY requirements.txt . RUN pip install --upgrade pip diff --git a/object-detection/Containerfile b/object-detection/Containerfile new file mode 100644 index 0000000..b98d502 --- /dev/null +++ b/object-detection/Containerfile @@ -0,0 +1,8 @@ +FROM registry.access.redhat.com/ubi9/python-311:1-66.1720018730 +WORKDIR /locallm +COPY requirements.txt /locallm/requirements.txt +RUN pip install --upgrade pip && \ + pip install --no-cache-dir --upgrade -r requirements.txt +COPY object_detection_client.py object_detection_client.py +EXPOSE 8501 +ENTRYPOINT [ "streamlit", "run", "object_detection_client.py" ] diff --git a/object-detection/object_detection_client.py b/object-detection/object_detection_client.py new file mode 100644 index 0000000..10450c2 --- /dev/null +++ b/object-detection/object_detection_client.py @@ -0,0 +1,38 @@ +import streamlit as st +import base64 +import requests +from PIL import Image +import os +import io + +st.title("🕵️‍♀️ Object Detection") +endpoint =os.getenv("MODEL_ENDPOINT", default = "http://0.0.0.0:8000") +headers = {"accept": "application/json", + "Content-Type": "application/json"} +image = st.file_uploader("Upload Image") +window = st.empty() + +if image: + #Ensure image dimensions are appropriate + img = Image.open(io.BytesIO(image.read())) + scale_factor = (500 * 500)/(img.height * img.width) + if scale_factor < 0.20: + scale_factor = 0.20 + img = img.resize((int(img.width * scale_factor) , + int(img.height * scale_factor))) + window.image(img, use_column_width=True) + # convert PIL image into bytes for post request + bytes_io = io.BytesIO() + if img.mode in ("RGBA", "P"): + img = img.convert("RGB") + img.save(bytes_io, "JPEG") + img_bytes = bytes_io.getvalue() + b64_image = base64.b64encode(img_bytes).decode('utf-8') + data = {'image': b64_image} + response = requests.post(f'{endpoint}/detection', headers=headers,json=data, verify=False) + # parse response and display outputs + response_json = response.json() + image = response_json["image"] + window.image(base64.b64decode(image), use_column_width=True) + for box in response_json["boxes"]: + st.markdown(box) diff --git a/object-detection/requirements.txt b/object-detection/requirements.txt new file mode 100644 index 0000000..ad64d16 --- /dev/null +++ b/object-detection/requirements.txt @@ -0,0 +1,40 @@ +altair==5.3.0 +attrs==23.2.0 +blinker==1.7.0 +cachetools==5.3.3 +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +gitdb==4.0.11 +GitPython==3.1.43 +idna==3.7 +Jinja2==3.1.4 +jsonschema==4.21.1 +jsonschema-specifications==2023.12.1 +markdown-it-py==3.0.0 +MarkupSafe==2.1.5 +mdurl==0.1.2 +numpy==1.26.4 +packaging==24.0 +pandas==2.2.2 +pillow==10.3.0 +protobuf==4.25.3 +pyarrow==15.0.2 +pydeck==0.8.1b0 +Pygments==2.17.2 +python-dateutil==2.9.0.post0 +pytz==2024.1 +referencing==0.34.0 +requests==2.31.0 +rich==13.7.1 +rpds-py==0.18.1 +six==1.16.0 +smmap==5.0.1 +streamlit==1.33.0 +tenacity==8.2.3 +toml==0.10.2 +toolz==0.12.1 +tornado==6.4.1 +typing_extensions==4.11.0 +tzdata==2024.1 +urllib3==2.2.2 diff --git a/pull-sample-app.sh b/pull-sample-app.sh index a7c020e..11c9b69 100755 --- a/pull-sample-app.sh +++ b/pull-sample-app.sh @@ -1,8 +1,9 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -CHATBOT_DIR=$ROOT_DIR/chatbot -CODEGEN_DIR=$ROOT_DIR/codegen -AUDIO_TO_TEXT_DIR=$ROOT_DIR/audio-to-text +CHATBOT_DIR=$ROOT_DIR/chatbot/ +CODEGEN_DIR=$ROOT_DIR/codegen/ +AUDIO_TO_TEXT_DIR=$ROOT_DIR/audio-to-text/ +OBJECTION_DETECTION_DIR=$ROOT_DIR/object-detection/ REPO="https://github.com/containers/ai-lab-recipes" @@ -14,8 +15,9 @@ git clone $REPO 2>&1 > /dev/null REPONAME=$(basename $REPO) -cp -r $TEMPDIR/$REPONAME/recipes/natural_language_processing/chatbot/app/ $CHATBOT_DIR/ -cp -r $TEMPDIR/$REPONAME/recipes/natural_language_processing/codegen/app/ $CODEGEN_DIR/ -cp -r $TEMPDIR/$REPONAME/recipes/audio/audio_to_text/app/ $AUDIO_TO_TEXT_DIR/ +cp -r $TEMPDIR/$REPONAME/recipes/natural_language_processing/chatbot/app/ $CHATBOT_DIR +cp -r $TEMPDIR/$REPONAME/recipes/natural_language_processing/codegen/app/ $CODEGEN_DIR +cp -r $TEMPDIR/$REPONAME/recipes/audio/audio_to_text/app/ $AUDIO_TO_TEXT_DIR +cp -r $TEMPDIR/$REPONAME/recipes/computer_vision/object_detection/app/ $OBJECTION_DETECTION_DIR rm -rf $TEMPDIR # clean up \ No newline at end of file