-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (63 loc) · 2.03 KB
/
app.py
File metadata and controls
83 lines (63 loc) · 2.03 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
import base64
import requests
from PIL import Image
import io
#################################
#needful functions
#to resize images
# def image_resizer(image1, image2):
# #first image
# #second image will be resized bbased on image1 dimension
# img1 = Image.open(image1)
# size1 = img1.size[0]
# size2 = img1.size[1]
# #resizing the second image
# img2 = Image.open(image2)
# img3 = img2.resize((size1, size2))
# img3.show()
# return img3
#to get predictions
def get_prediction(image_data):
#replace your image classification ai service URL
url = 'https://askai.aiclub.world/7dfcf802-add4-4654-8fb9-4ebe5edc4992'
r = requests.post(url, data=image_data)
response = r.json()['predicted_label']
return response
#################################
#creating the web app
#title for the web app
st.title("🐱 Cats & Dogs Classifier 🐶")
#subheader
st.subheader("About the projct..")
#write elements
st.write("**This web can be used to classify images of cats and dogs. AI was trained in Navigator with AI Club datasets.**")
#showing cats images
st.image("cats.jpg", caption = "Picture of cats")
#showing dogs images
st.image("dogs.jpg", caption = "Picture of dogs")
#file uploading and prediction part
image = st.file_uploader(label="Upload an image",accept_multiple_files=False, help="Upload an image to classify them")
if image:
#converting the image to bytes
img = Image.open(image)
#image to be predicted
st.image(img, caption = "Image to be predicted")
#converting the image to bytes
buf = io.BytesIO()
img.save(buf,format = 'JPEG')
byte_im = buf.getvalue()
#converting bytes to b64encoding
payload = base64.b64encode(byte_im)
#file details
file_details = {
"file name": image.name,
"file type": image.type,
"file size": image.size
}
#write file details
st.write(file_details)
#predictions
response = get_prediction(payload)
#prediction label
st.markdown("This is a **{}**".format(response.split('s')[0]))