Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,13 @@ def predict(input_dict):
|
|
10 |
if not input_dict or "composite" not in input_dict:
|
11 |
return {str(i): 0.0 for i in range(10)}
|
12 |
|
|
|
13 |
image = input_dict["composite"]
|
14 |
|
|
|
|
|
|
|
|
|
15 |
# Remove alpha channel (RGBA → RGB)
|
16 |
image = image[:, :, :3]
|
17 |
|
@@ -26,6 +31,9 @@ def predict(input_dict):
|
|
26 |
image = image / 255.0
|
27 |
image = image.numpy().reshape(-1, 28, 28, 1)
|
28 |
|
|
|
|
|
|
|
29 |
# Predict
|
30 |
prediction = model.predict(image)
|
31 |
probs = tf.nn.softmax(prediction[0]).numpy()
|
|
|
10 |
if not input_dict or "composite" not in input_dict:
|
11 |
return {str(i): 0.0 for i in range(10)}
|
12 |
|
13 |
+
|
14 |
image = input_dict["composite"]
|
15 |
|
16 |
+
MAX_INTENSITY_SUM = 0.005272861870622912
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
# Remove alpha channel (RGBA → RGB)
|
21 |
image = image[:, :, :3]
|
22 |
|
|
|
31 |
image = image / 255.0
|
32 |
image = image.numpy().reshape(-1, 28, 28, 1)
|
33 |
|
34 |
+
if np.sum(image) > MAX_INTENSITY_SUM:
|
35 |
+
return "Please try Again"
|
36 |
+
|
37 |
# Predict
|
38 |
prediction = model.predict(image)
|
39 |
probs = tf.nn.softmax(prediction[0]).numpy()
|