Spaces:
Runtime error
Runtime error
Updated UI
Browse files
app.py
CHANGED
|
@@ -60,13 +60,12 @@ def main():
|
|
| 60 |
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 61 |
|
| 62 |
if uploaded_file is not None:
|
| 63 |
-
# Load model
|
| 64 |
-
model = load_model()
|
| 65 |
-
|
| 66 |
# Display uploaded image
|
| 67 |
image = Image.open(io.BytesIO(uploaded_file.read()))
|
| 68 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# Predict button
|
| 72 |
predict_button = st.sidebar.button("Predict", key="predict_button")
|
|
@@ -78,6 +77,8 @@ def main():
|
|
| 78 |
if predict_button:
|
| 79 |
# Display processing message with spinner
|
| 80 |
with st.spinner("Please wait...Processing the image and predicting..."):
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Classify image
|
| 83 |
predicted_class, confidence_score = predict(model, image)
|
|
@@ -85,17 +86,17 @@ def main():
|
|
| 85 |
# Explain image classification
|
| 86 |
explanation_image = explain_image(processed_image, model)
|
| 87 |
|
| 88 |
-
# Display
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# Display prediction
|
| 92 |
st.subheader("Prediction:")
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
"Predicted Class": [predicted_class],
|
| 96 |
-
"Confidence": [f"{confidence_score}%"]
|
| 97 |
-
})
|
| 98 |
-
st.table(prediction_table)
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
| 101 |
main()
|
|
|
|
| 60 |
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 61 |
|
| 62 |
if uploaded_file is not None:
|
|
|
|
|
|
|
|
|
|
| 63 |
# Display uploaded image
|
| 64 |
image = Image.open(io.BytesIO(uploaded_file.read()))
|
| 65 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 66 |
+
|
| 67 |
+
# Load model
|
| 68 |
+
model = load_model()
|
| 69 |
|
| 70 |
# Predict button
|
| 71 |
predict_button = st.sidebar.button("Predict", key="predict_button")
|
|
|
|
| 77 |
if predict_button:
|
| 78 |
# Display processing message with spinner
|
| 79 |
with st.spinner("Please wait...Processing the image and predicting..."):
|
| 80 |
+
# Preprocess image
|
| 81 |
+
processed_image = preprocess_image(image)
|
| 82 |
|
| 83 |
# Classify image
|
| 84 |
predicted_class, confidence_score = predict(model, image)
|
|
|
|
| 86 |
# Explain image classification
|
| 87 |
explanation_image = explain_image(processed_image, model)
|
| 88 |
|
| 89 |
+
# Display images side by side
|
| 90 |
+
col1, col2 = st.columns(2)
|
| 91 |
+
with col1:
|
| 92 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 93 |
+
with col2:
|
| 94 |
+
st.image(explanation_image, caption="Explanation Image", use_column_width=True)
|
| 95 |
|
| 96 |
# Display prediction
|
| 97 |
st.subheader("Prediction:")
|
| 98 |
+
st.write(f"Predicted Class: {predicted_class}")
|
| 99 |
+
st.write(f"Confidence Score: {confidence_score}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
| 102 |
main()
|