JAI03 commited on
Commit
e1007af
·
verified ·
1 Parent(s): 4ff9455

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow
3
+ from tensorflow.keras.models import load_model
4
+ import numpy as np
5
+ from PIL import Image
6
+ import pandas as pd
7
+ import os
8
+
9
+ # Load the saved TensorFlow model
10
+ model = load_model('traffic-sign-detection-model3.h5')
11
+
12
+
13
+ inputBasePath = 'D:\\traffic_Data\\'
14
+ path = 'D:\\traffic_Data\\DATA'
15
+ testingFolder = 'D:\\traffic_Data\\TEST'
16
+ classes = pd.read_csv(os.path.join(inputBasePath,'labels.csv'))
17
+
18
+
19
+ # Function to preprocess the image
20
+ def preprocess_image(image):
21
+ # Preprocess the image as required for your model
22
+ # (e.g., resize, normalize pixel values)
23
+ resized_image = image.resize((100,100))
24
+ preprocessed_image = np.array(resized_image) / 255.0 # Normalize pixel values
25
+ return preprocessed_image
26
+
27
+ # Function to make predictions
28
+ def predict(image):
29
+ preprocessed_image = preprocess_image(image)
30
+ prediction = model.predict(np.expand_dims(preprocessed_image, axis=0))
31
+ return prediction
32
+
33
+ # Streamlit app
34
+ def main():
35
+ st.title('Traffic Sign Detection')
36
+
37
+ uploaded_image = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
38
+
39
+ if uploaded_image is not None:
40
+ # Display the uploaded image
41
+ image = Image.open(uploaded_image)
42
+ st.image(image, caption='Uploaded Image', use_column_width=True)
43
+
44
+ # Predict button
45
+ if st.button('Predict'):
46
+ # Make prediction
47
+ prediction = predict(image)
48
+ predicted_class = np.argmax(prediction, axis=1)
49
+ #st.write(predicted_class)
50
+ class_mapping = dict(zip(classes['ClassId'], classes['Name']))
51
+ predicted_label = class_mapping.get(predicted_class[0])
52
+ # st.write(predicted_label)
53
+ # st.write(predicted_class)
54
+
55
+ # Display prediction result
56
+
57
+ st.write('Prediction:', predicted_label)
58
+
59
+ if __name__ == '__main__':
60
+ main()