Gosula commited on
Commit
5c00344
·
1 Parent(s): 9ded5df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -27
app.py CHANGED
@@ -78,16 +78,6 @@ cnn.fit(XCnn_train, y_train)
78
  # Set the page title
79
  st.title("Handwritten Text Digit Recognition")
80
 
81
- # Create a CSS style to center-align text
82
- centered_title = f"""
83
- <div style="text-align: center; padding: 10px;">
84
- <h1>Handwritten Text Digit Recognition</h1>
85
- </div>
86
- """
87
- # Display the centered title
88
- st.markdown(centered_title, unsafe_allow_html=True)
89
-
90
-
91
  stroke_width = st.sidebar.slider("Stroke width: ", 1, 35, 32)
92
  stroke_color = st.sidebar.color_picker("Stroke color hex: ")
93
  bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
@@ -111,28 +101,16 @@ canvas_result = st_canvas(
111
 
112
  # Do something interesting with the image data and paths
113
  if canvas_result.image_data is not None:
114
- # Preprocess the drawn image
115
  image = canvas_result.image_data
116
  image1 = image.copy()
117
  image1 = image1.astype('uint8')
118
-
119
- # Assuming the background is white, you can invert the colors if necessary
120
- image1 = 255 - image1
121
-
122
- # Resize the image to match the input size of your CNN model (28x28)
123
  image1 = cv2.resize(image1, (28, 28))
124
-
125
- # Normalize the image to values between 0 and 1
126
- image1 = image1 / 255.0
127
-
128
- # Convert the image to the expected shape for the model
129
- image1 = image1.reshape(1, 1, 28, 28).astype('float32')
130
 
131
- # Pass the preprocessed image to your model for prediction
132
- prediction = np.argmax(cnn.predict(image1))
133
-
134
- # Display the prediction result
135
- st.title(f"Predicted Digit: {prediction}")
136
 
137
  if canvas_result.json_data is not None:
138
  st.dataframe(pd.json_normalize(canvas_result.json_data["objects"]))
 
78
  # Set the page title
79
  st.title("Handwritten Text Digit Recognition")
80
 
 
 
 
 
 
 
 
 
 
 
81
  stroke_width = st.sidebar.slider("Stroke width: ", 1, 35, 32)
82
  stroke_color = st.sidebar.color_picker("Stroke color hex: ")
83
  bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
 
101
 
102
  # Do something interesting with the image data and paths
103
  if canvas_result.image_data is not None:
 
104
  image = canvas_result.image_data
105
  image1 = image.copy()
106
  image1 = image1.astype('uint8')
107
+ image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
 
 
 
 
108
  image1 = cv2.resize(image1, (28, 28))
109
+ st.image(image1)
 
 
 
 
 
110
 
111
+ # Correctly reshape the image
112
+ image1 = image1.reshape(1, 1, 28, 28).astype('float32')
113
+ st.title(np.argmax(model.predict(image1)))
 
 
114
 
115
  if canvas_result.json_data is not None:
116
  st.dataframe(pd.json_normalize(canvas_result.json_data["objects"]))