sarahai commited on
Commit
06f4e6b
·
verified ·
1 Parent(s): 4749310

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from keras.models import load_model
3
+ from PIL import Image, ImageOps
4
+ import numpy as np
5
+
6
+
7
+ model = load_model("keras_model.h5", compile=False)
8
+
9
+
10
+ class_names = open("labels.txt", "r").readlines()
11
+
12
+
13
+ def predict(image):
14
+
15
+ data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
16
+ # Preprocess
17
+ image = ImageOps.fit(image, (224, 224), Image.LANCZOS)
18
+ image_array = np.asarray(image)
19
+ normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
20
+ data[0] = normalized_image_array
21
+ # Make prediction
22
+ prediction = model.predict(data)
23
+ index = np.argmax(prediction)
24
+ class_name = class_names[index].strip()
25
+ confidence_score = prediction[0][index]
26
+ return class_name, confidence_score
27
+
28
+
29
+ st.title("Image Classification")
30
+
31
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
32
+
33
+ if uploaded_file is not None:
34
+ image = Image.open(uploaded_file).convert("RGB")
35
+ st.image(image, caption="Uploaded Image", use_column_width=True)
36
+ class_name, confidence_score = predict(image)
37
+ st.write("Class:", class_name)
38
+ st.write("Confidence Score:", confidence_score)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow