-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from yangcao77/add-object-detection
Add object detection app
- Loading branch information
Showing
7 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters