Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- app.py +64 -0
- ksl_model.pkl +3 -0
- requirements.txt +5 -0
- tempDir/ImageID_00AVE728.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
import numpy as np
|
4 |
+
import PIL.Image
|
5 |
+
#from PIL import Image
|
6 |
+
from fastai.vision.all import *
|
7 |
+
import pathlib
|
8 |
+
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
|
11 |
+
|
12 |
+
temp = pathlib.PosixPath
|
13 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
14 |
+
|
15 |
+
model = load_learner('ksl_model.pkl')
|
16 |
+
|
17 |
+
def predict(image_path):
|
18 |
+
# load the image and convert into
|
19 |
+
# numpy array
|
20 |
+
#image= Image.open(image)
|
21 |
+
# image = Image.open(image)
|
22 |
+
# PIL images into NumPy arrays
|
23 |
+
pred_label= model.predict(image_path)
|
24 |
+
|
25 |
+
return pred_label
|
26 |
+
|
27 |
+
|
28 |
+
def show_likelihood(pred_label):
|
29 |
+
class_probs = pred_label[2].numpy()
|
30 |
+
classes = ["Temple", "You", "Me", "You", "Friend", "Love", "Enough", "Church","Mosque"]
|
31 |
+
class_labels = [classes[i] for i in range(len(class_probs))]
|
32 |
+
fig = plt.figure(figsize=(10, 10))
|
33 |
+
plt.barh(class_labels, class_probs)
|
34 |
+
plt.ylabel("Class")
|
35 |
+
plt.xlabel("Probability")
|
36 |
+
plt.title("Class Probabilities")
|
37 |
+
plt.xlim(0, 1)
|
38 |
+
plt.ylim(-1, len(class_probs))
|
39 |
+
st.pyplot(fig)
|
40 |
+
|
41 |
+
def main():
|
42 |
+
st.set_page_config(page_title="Image Classification App", page_icon=":camera:", layout="wide")
|
43 |
+
|
44 |
+
st.write("# KSL Image Classification App")
|
45 |
+
st.write("This app allows you to upload an image and have it classified by a trained machine learning model.")
|
46 |
+
|
47 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
48 |
+
if uploaded_file is not None:
|
49 |
+
|
50 |
+
image = PIL.Image.open(uploaded_file)
|
51 |
+
|
52 |
+
image_path = os.path.join("tempDir",uploaded_file.name)
|
53 |
+
|
54 |
+
with open(image_path, "wb") as f:
|
55 |
+
f.write(uploaded_file.getbuffer())
|
56 |
+
|
57 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
58 |
+
pred_label = predict(image_path)
|
59 |
+
st.write("The image was classified as:", pred_label[0])
|
60 |
+
|
61 |
+
show_likelihood(pred_label)
|
62 |
+
|
63 |
+
if __name__ == '__main__':
|
64 |
+
main()
|
ksl_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0154c80331d40908a24272d12e6186a50d3e5a8aaa13e7a5232c61e44dd4ef62
|
3 |
+
size 87748741
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastai==2.7.10
|
2 |
+
matplotlib==3.6.3
|
3 |
+
numpy==1.23.5
|
4 |
+
Pillow==9.4.0
|
5 |
+
streamlit==1.18.1
|
tempDir/ImageID_00AVE728.jpg
ADDED
![]() |