-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
46 lines (34 loc) · 1.14 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
from PIL import Image
import requests
from dotenv import load_dotenv
import os
import boto3
# take environment variables from .env
load_dotenv()
# Lambda URL
url = os.getenv("AWS_LAMBDA_URL")
# s3 bucket url
s3_bucket_url = os.getenv('S3_BUCKET_URL')
# set title
st.title('Birds Classifier')
# set header
st.header('Upload an image of the bird')
# upload file
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
# display image
if uploaded_file is not None:
image = Image.open(uploaded_file).convert('RGB')
st.image(image, use_column_width=False, width=300)
# Save the image to a file
image.save("temp.jpg", format="JPEG")
# Upload the file to S3
s3 = boto3.client('s3')
with open("temp.jpg", "rb") as data:
s3.upload_fileobj(data, 'birds-classification', 'myimage.jpg')
# Now 'myimage.jpg' is accessible
img_url = f'{s3_bucket_url}/myimage.jpg'
# Send the image URL as JSON data
result = requests.post(url, json={"url": img_url})
# write classification
st.write(f"**Bird Category Prediction**: 👉👉👉{result.json()}👈👈👈")