atticus-carter
commited on
Commit
•
ca9f6e0
1
Parent(s):
1c738c0
Update app.py
Browse files
app.py
CHANGED
@@ -18,21 +18,16 @@ st.write("This app uses a YOLO model to detect benthic megafauna in images.")
|
|
18 |
# Load example images
|
19 |
examples = glob.glob("images/*.png")
|
20 |
|
21 |
-
#
|
22 |
st.sidebar.title("Example Images")
|
23 |
selected_example = st.sidebar.selectbox("Select an example image", examples)
|
24 |
|
25 |
-
# Display the selected example image
|
26 |
-
if selected_example:
|
27 |
-
st.image(selected_example, caption="Selected Example Image", use_column_width=True)
|
28 |
-
|
29 |
# File uploader for custom images
|
30 |
uploaded_file = st.file_uploader("Or upload an image", type=["png", "jpg", "jpeg"])
|
31 |
|
32 |
# Select which image to use for prediction
|
33 |
if uploaded_file is not None:
|
34 |
image = Image.open(uploaded_file)
|
35 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
36 |
image_path = uploaded_file
|
37 |
elif selected_example:
|
38 |
image = Image.open(selected_example)
|
@@ -41,9 +36,27 @@ else:
|
|
41 |
image = None
|
42 |
image_path = None
|
43 |
|
44 |
-
# Run the YOLO model
|
45 |
if image_path is not None:
|
46 |
results = model.predict(image_path, **PREDICT_KWARGS)
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
else:
|
49 |
st.write("Please upload an image or select an example to proceed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Load example images
|
19 |
examples = glob.glob("images/*.png")
|
20 |
|
21 |
+
# Sidebar for selecting example images
|
22 |
st.sidebar.title("Example Images")
|
23 |
selected_example = st.sidebar.selectbox("Select an example image", examples)
|
24 |
|
|
|
|
|
|
|
|
|
25 |
# File uploader for custom images
|
26 |
uploaded_file = st.file_uploader("Or upload an image", type=["png", "jpg", "jpeg"])
|
27 |
|
28 |
# Select which image to use for prediction
|
29 |
if uploaded_file is not None:
|
30 |
image = Image.open(uploaded_file)
|
|
|
31 |
image_path = uploaded_file
|
32 |
elif selected_example:
|
33 |
image = Image.open(selected_example)
|
|
|
36 |
image = None
|
37 |
image_path = None
|
38 |
|
39 |
+
# Run the YOLO model and display the results side by side
|
40 |
if image_path is not None:
|
41 |
results = model.predict(image_path, **PREDICT_KWARGS)
|
42 |
+
prediction_image = results[0].plot()[:, :, ::-1] # Processed image with predictions
|
43 |
+
|
44 |
+
# Create two columns for side-by-side display
|
45 |
+
col1, col2 = st.columns(2)
|
46 |
+
|
47 |
+
with col1:
|
48 |
+
st.image(image, caption="Selected Image", use_column_width=True)
|
49 |
+
|
50 |
+
with col2:
|
51 |
+
st.image(prediction_image, caption="Predicted Image", use_column_width=True)
|
52 |
else:
|
53 |
st.write("Please upload an image or select an example to proceed.")
|
54 |
+
|
55 |
+
# Footer with copyright and image credit
|
56 |
+
st.markdown(
|
57 |
+
"""
|
58 |
+
---
|
59 |
+
**© 2024 Atticus Carter, [https://oceancv.org/](https://oceancv.org/)**
|
60 |
+
**Image Credit: Ocean Observatories Initiative 2022**
|
61 |
+
"""
|
62 |
+
)
|