Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,29 +26,22 @@ def predict_image(image):
|
|
| 26 |
# Make a prediction
|
| 27 |
prediction = model.predict(image)
|
| 28 |
|
| 29 |
-
# Get the probability of being '
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
#predict_label = "Clean"
|
| 42 |
-
#else:
|
| 43 |
-
#predict_label = "Carries"
|
| 44 |
-
#confidence = float(np.max(predictions))
|
| 45 |
-
#prediction_dict = {"prediction": predict_label, "confidence": confidence}
|
| 46 |
-
#return prediction_dict
|
| 47 |
-
|
| 48 |
|
| 49 |
|
| 50 |
# Create the interface
|
| 51 |
-
input_interface = gr.Image(type
|
| 52 |
output_interface = "json"
|
| 53 |
|
| 54 |
iface = gr.Interface(
|
|
|
|
| 26 |
# Make a prediction
|
| 27 |
prediction = model.predict(image)
|
| 28 |
|
| 29 |
+
# Get the probability of being 'Clean' or 'Carries'
|
| 30 |
+
probabilities = tf.nn.softmax(prediction, axis=-1)
|
| 31 |
+
predicted_class_index = np.argmax(probabilities)
|
| 32 |
+
if predicted_class_index == 0:
|
| 33 |
+
predicted_label = "Clean"
|
| 34 |
+
else:
|
| 35 |
+
predicted_label = "Carries"
|
| 36 |
+
confidence = float(np.max(probabilities))
|
| 37 |
+
confidence = str(confidence)
|
| 38 |
+
# Print the predicted label and evaluation
|
| 39 |
+
# Return the prediction result as a dictionary
|
| 40 |
+
return {"Predicted Label:", predicted_label, f"Evaluate the topic according to {predicted_label} is: {confidence}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
# Create the interface
|
| 44 |
+
input_interface = gr.Image(type="pil")
|
| 45 |
output_interface = "json"
|
| 46 |
|
| 47 |
iface = gr.Interface(
|