Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object detection app #8

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion audio-to-text/Containerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
2 changes: 1 addition & 1 deletion chatbot/Containerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion codegen/Containerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions object-detection/Containerfile
Original file line number Diff line number Diff line change
@@ -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" ]
38 changes: 38 additions & 0 deletions object-detection/object_detection_client.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions object-detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions pull-sample-app.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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