Abdul-Haseeb commited on
Commit
bdd33e5
·
verified ·
1 Parent(s): f53f171

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -52
app.py CHANGED
@@ -1,53 +1,52 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
- from PIL import Image
5
- import matplotlib.pyplot as plt
6
- import tensorflow as tf
7
- from tensorflow import keras
8
- from tensorflow.keras.models import load_model
9
- from tensorflow.keras.preprocessing import image
10
- from tensorflow.keras.applications.efficientnet import preprocess_input
11
-
12
- def predict(uploaded_file, model, classes):
13
- img = Image.open(uploaded_file)
14
- img = img.resize((300, 300))
15
- img_array = np.array(img)
16
- img_array = np.expand_dims(img_array, axis=0)
17
- img_array = preprocess_input(img_array)
18
-
19
- prediction = model.predict(img_array)
20
- predicted_class_index = np.argmax(prediction)
21
- predicted_class_label = classes[predicted_class_index]
22
-
23
- st.write(f"Predicted Vehicle: {predicted_class_label}")
24
- st.image(img, use_column_width=True)
25
-
26
- def run():
27
- st.header('Vehicle Type Recognition :busstop:')
28
- st.write('The objective of this project is to build a machine learning model to classify vehicles into the following categories using Convolutional Neural Networks.')
29
- st.markdown("""
30
- - Auto Rickshaw :auto_rickshaw:
31
- - Bicycle :bicyclist:
32
- - Bus :bus:
33
- - Car :car:
34
- - Motorcycle :racing_motorcycle:
35
- - Truck :truck:
36
- - Van :minibus:
37
- """)
38
-
39
- with st.form(key='Form Upload Vehicle Type Recognition'):
40
- uploaded_files = st.file_uploader("Choose a .JPEG/.JPG/.PNG file", accept_multiple_files=True)
41
-
42
- if uploaded_files:
43
- for uploaded_file in uploaded_files:
44
-
45
- st.write("filename:", uploaded_file.name)
46
- model = load_model('vehicle_recognition_model.keras')
47
- classes = ['Auto-rickshaw :auto_rickshaw:', 'Bicycle :bicyclist:', 'Bus :bus:', 'Car :car:', 'Motorcycle :racing_motorcycle:', 'Truck :truck:', 'Van :minibus:']
48
- predict(uploaded_file, model, classes)
49
-
50
- st.form_submit_button(label='Submit')
51
-
52
- if __name__ == '__main__':
53
  run()
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from PIL import Image
5
+ import tensorflow as tf
6
+ from tensorflow import keras
7
+ from tensorflow.keras.models import load_model
8
+ from tensorflow.keras.preprocessing import image
9
+ from tensorflow.keras.applications.efficientnet import preprocess_input
10
+
11
+ def predict(uploaded_file, model, classes):
12
+ img = Image.open(uploaded_file)
13
+ img = img.resize((300, 300))
14
+ img_array = np.array(img)
15
+ img_array = np.expand_dims(img_array, axis=0)
16
+ img_array = preprocess_input(img_array)
17
+
18
+ prediction = model.predict(img_array)
19
+ predicted_class_index = np.argmax(prediction)
20
+ predicted_class_label = classes[predicted_class_index]
21
+
22
+ st.write(f"Predicted Vehicle: {predicted_class_label}")
23
+ st.image(img, use_column_width=True)
24
+
25
+ def run():
26
+ st.header('Vehicle Type Recognition :busstop:')
27
+ st.write('The objective of this project is to build a machine learning model to classify vehicles into the following categories using Convolutional Neural Networks.')
28
+ st.markdown("""
29
+ - Auto Rickshaw :auto_rickshaw:
30
+ - Bicycle :bicyclist:
31
+ - Bus :bus:
32
+ - Car :car:
33
+ - Motorcycle :racing_motorcycle:
34
+ - Truck :truck:
35
+ - Van :minibus:
36
+ """)
37
+
38
+ with st.form(key='Form Upload Vehicle Type Recognition'):
39
+ uploaded_files = st.file_uploader("Choose a .JPEG/.JPG/.PNG file", accept_multiple_files=True)
40
+
41
+ if uploaded_files:
42
+ for uploaded_file in uploaded_files:
43
+
44
+ st.write("filename:", uploaded_file.name)
45
+ model = load_model('vehicle_recognition_model.keras')
46
+ classes = ['Auto-rickshaw :auto_rickshaw:', 'Bicycle :bicyclist:', 'Bus :bus:', 'Car :car:', 'Motorcycle :racing_motorcycle:', 'Truck :truck:', 'Van :minibus:']
47
+ predict(uploaded_file, model, classes)
48
+
49
+ st.form_submit_button(label='Submit')
50
+
51
+ if __name__ == '__main__':
 
52
  run()