edesaras commited on
Commit
c120c7a
·
verified ·
1 Parent(s): 7928abd

Upload folder using huggingface_hub

Browse files

fixed streamlit st.cache deprecated error, example images are bigger

Files changed (1) hide show
  1. app.py +4 -3
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.cache(allow_output_mutation=True)
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=32, line_width=2) # 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,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(['example1.jpg', 'example2.jpg'], width=300, caption=['Example 1', 'Example 2'])
 
 
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')