Update app.py
Browse files
app.py
CHANGED
@@ -8,16 +8,9 @@ model = tf.keras.models.load_model("cnn_model.h5")
|
|
8 |
|
9 |
def predict(image_array):
|
10 |
try:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Handle if input is a dictionary (which appears to be happening)
|
15 |
-
if isinstance(image_array, dict):
|
16 |
-
# If it's a dict, try to get the image data
|
17 |
-
if "image" in image_array:
|
18 |
-
image_array = image_array["image"]
|
19 |
-
else:
|
20 |
-
return "Error: Received dictionary input but couldn't find image data"
|
21 |
|
22 |
if image_array is None or np.sum(image_array) == 0:
|
23 |
return "Please draw a digit."
|
@@ -31,7 +24,7 @@ def predict(image_array):
|
|
31 |
confidence = float(tf.nn.softmax(logits)[0][prediction])
|
32 |
return f"Digit: {prediction} (confidence: {confidence:.2%})"
|
33 |
except Exception as err:
|
34 |
-
return f"Runtime error: {str(err)}
|
35 |
|
36 |
gr.Interface(
|
37 |
fn=predict,
|
|
|
8 |
|
9 |
def predict(image_array):
|
10 |
try:
|
11 |
+
if isinstance(image_array, dict) and 'composite' in image_array:
|
12 |
+
# Extract the image data from the 'composite' key
|
13 |
+
image_array = image_array['composite']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
if image_array is None or np.sum(image_array) == 0:
|
16 |
return "Please draw a digit."
|
|
|
24 |
confidence = float(tf.nn.softmax(logits)[0][prediction])
|
25 |
return f"Digit: {prediction} (confidence: {confidence:.2%})"
|
26 |
except Exception as err:
|
27 |
+
return f"Runtime error: {str(err)}"
|
28 |
|
29 |
gr.Interface(
|
30 |
fn=predict,
|