-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
43 lines (36 loc) · 1.43 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
import streamlit as st
from roboflow import Roboflow
from PIL import Image
import numpy as np
rf = Roboflow(st.secrets.api_key)
project = rf.workspace().project("arabic-sl")
model = project.version(17).model
#UI
st.title("Image Classification with Streamlit")
option = st.selectbox(
'Select the approach to test the model',
('UploadImage', 'CameraInput'))
if option == 'UploadImage':
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_image is not None:
with open("uploaded_image.png", "wb") as f:
f.write(uploaded_image.read())
st.success("Image saved successfully!")
#Read the saved image
saved_image = st.image("uploaded_image.png", caption='Uploaded Image.', use_column_width=True)
predicted = model.predict(
"uploaded_image.png",
confidence=20, overlap=30).json()
st.write("Predicted Class:", predicted)
elif option == 'CameraInput':
st.write("Camera Input")
picture = st.camera_input("Take a picture")
if picture is not None:
img = Image.open(picture)
st.image(img, caption='Uploaded Image.', use_column_width=True)
img_array=np.array(img)
img_array.resize((640, 640))
#picture = picture.thumbnail((640, 640))
predicted = model.predict(img_array,
confidence=20, overlap=30).json()
st.write("Predicted Class:", predicted)