FerdiErs commited on
Commit
3da4337
·
1 Parent(s): a33849c

Commit Model Deployment

Browse files
Files changed (3) hide show
  1. app.py +57 -0
  2. model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ import os
5
+ import tensorflow as tf
6
+ from keras.applications.xception import preprocess_input, decode_predictions
7
+ from keras.applications.xception import Xception
8
+ from keras.preprocessing.image import load_img, img_to_array
9
+ from keras.models import load_model
10
+
11
+ # Load the model
12
+ model = load_model('model.h5')
13
+
14
+ # Function to treshold
15
+ def Predict(value):
16
+ if value >= 0.5:
17
+ return "Car"
18
+ else:
19
+ return "Bike"
20
+
21
+ # Function to preprocess the uploaded image
22
+ def preprocess_image(image):
23
+ img = load_img(image, target_size=(200, 200))
24
+ img_array = img_to_array(img) / 255.0
25
+ img_resized = tf.image.resize(img_array, (200, 200))
26
+ img_batch = tf.expand_dims(img_resized, axis=0)
27
+ return img_batch
28
+
29
+ # Function to predict the image
30
+ def predict_image(image):
31
+ img_array = preprocess_image(image)
32
+ predictions = model.predict(img_array)
33
+ return predictions[0][0]
34
+
35
+ def main():
36
+ st.title("Image Classification")
37
+
38
+ uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
39
+
40
+ if uploaded_image is not None:
41
+ st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)
42
+
43
+ # Save the uploaded image temporarily
44
+ temp_image_path = "temp_image.jpg"
45
+ with open(temp_image_path, 'wb') as f:
46
+ f.write(uploaded_image.read())
47
+
48
+ # Perform prediction
49
+ prediction = predict_image(temp_image_path)
50
+ prediction_text = Predict(prediction)
51
+ st.write(f"Prediction: {prediction_text}")
52
+
53
+ # Remove the temporary image file
54
+ os.remove(temp_image_path)
55
+
56
+ if __name__ == '__main__':
57
+ main()
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b3f08ae1c63792fa3dc03aed8d6bfaeba0e5f5a6497f274d23b7ee8d6682c5a
3
+ size 86980992
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ opencv-python-headless
3
+ tensorflow
4
+ numpy