atticus-carter commited on
Commit
9012474
·
verified ·
1 Parent(s): 114efa7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -1,7 +1,9 @@
 
1
  import glob
2
- import gradio as gr
3
  from ultralytics import YOLO
 
4
 
 
5
  model_path = "best.pt"
6
  model = YOLO(model_path)
7
 
@@ -9,22 +11,39 @@ PREDICT_KWARGS = {
9
  "conf": 0.15,
10
  }
11
 
12
- def run(image_path):
13
- results = model.predict(image_path, **PREDICT_KWARGS)
14
- return results[0].plot()[:, :, ::-1] # reverse channels for gradio
15
-
16
- title = "OOI RCA Digital Still Camera Benthic Megafauna Detector"
17
- description = ""
18
 
 
19
  examples = glob.glob("images/*.png")
20
 
21
- interface = gr.Interface(
22
- run,
23
- inputs=[gr.components.Image(type="filepath")],
24
- outputs=gr.components.Image(type="numpy"),
25
- title=title,
26
- description=description,
27
- examples=examples,
28
- )
29
 
30
- interface.queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import glob
 
3
  from ultralytics import YOLO
4
+ from PIL import Image
5
 
6
+ # Load the YOLO model
7
  model_path = "best.pt"
8
  model = YOLO(model_path)
9
 
 
11
  "conf": 0.15,
12
  }
13
 
14
+ # Title and description for the app
15
+ st.title("OOI RCA Digital Still Camera Benthic Megafauna Detector")
16
+ st.write("This app uses a YOLO model to detect benthic megafauna in images.")
 
 
 
17
 
18
+ # Load example images
19
  examples = glob.glob("images/*.png")
20
 
21
+ # Display list of example images to choose from
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)
39
+ image_path = selected_example
40
+ else:
41
+ image = None
42
+ image_path = None
43
+
44
+ # Run the YOLO model on the selected image
45
+ if image_path is not None:
46
+ results = model.predict(image_path, **PREDICT_KWARGS)
47
+ st.image(results[0].plot()[:, :, ::-1], caption="Predicted Image", use_column_width=True)
48
+ else:
49
+ st.write("Please upload an image or select an example to proceed.")