Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesfixed streamlit st.cache deprecated error, example images are bigger
app.py
CHANGED
@@ -4,7 +4,7 @@ import numpy as np
|
|
4 |
from ultralytics import YOLO # Make sure this import works in your Hugging Face environment
|
5 |
|
6 |
# Load the model
|
7 |
-
@st.
|
8 |
def load_model():
|
9 |
model = YOLO("weights.pt") # Adjust path if needed
|
10 |
return model
|
@@ -25,7 +25,7 @@ if uploaded_file is not None:
|
|
25 |
# Perform inference
|
26 |
results = model.predict(uploaded_file)
|
27 |
r = results[0]
|
28 |
-
im_bgr = r.plot(conf=False, pil=True, font_size=
|
29 |
im_rgb = Image.fromarray(im_bgr[..., ::-1]) # Convert BGR to RGB
|
30 |
|
31 |
# Display the prediction
|
@@ -33,4 +33,5 @@ if uploaded_file is not None:
|
|
33 |
|
34 |
# Optionally, display pre-computed example images
|
35 |
if st.checkbox('Show Example Results'):
|
36 |
-
st.image(
|
|
|
|
4 |
from ultralytics import YOLO # Make sure this import works in your Hugging Face environment
|
5 |
|
6 |
# Load the model
|
7 |
+
@st.cache_resource(allow_output_mutation=True)
|
8 |
def load_model():
|
9 |
model = YOLO("weights.pt") # Adjust path if needed
|
10 |
return model
|
|
|
25 |
# Perform inference
|
26 |
results = model.predict(uploaded_file)
|
27 |
r = results[0]
|
28 |
+
im_bgr = r.plot(conf=False, pil=True, font_size=48, line_width=3) # Returns a PIL image if pil=True
|
29 |
im_rgb = Image.fromarray(im_bgr[..., ::-1]) # Convert BGR to RGB
|
30 |
|
31 |
# Display the prediction
|
|
|
33 |
|
34 |
# Optionally, display pre-computed example images
|
35 |
if st.checkbox('Show Example Results'):
|
36 |
+
st.image('example1.jpg', use_column_width=True, caption='Example 1')
|
37 |
+
st.image('example2.jpg', use_column_width=True, caption='Example 2')
|