Senasu commited on
Commit
f8565cd
·
verified ·
1 Parent(s): ef5521f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -5,6 +5,7 @@ import streamlit as st
5
  from PIL import Image
6
  from collections import Counter
7
  import os
 
8
 
9
  # Streamlit app title
10
  st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
@@ -21,30 +22,39 @@ The application will display the image with bounding boxes around the objects.
21
  st.markdown("### Step 1: Upload an Image for Object Detection")
22
  uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
23
 
24
- # Function to disable progress bar in cvlib download function
25
- def download_file_without_progress(url, file_name, dest_dir):
26
- """
27
- Downloads the file without displaying progress bar.
28
- """
29
  file_path = os.path.join(dest_dir, file_name)
30
  if not os.path.exists(file_path):
31
- # Perform the download without progress bar
32
  print(f"Downloading {file_name}...")
33
- os.system(f"wget {url} -O {file_path}")
 
 
 
 
 
34
  return file_path
35
 
36
- # Modify the detect_common_objects function to accept a skip_progress argument
37
  def detect_common_objects_skip_progress(image, model='yolov3', skip_progress=False):
38
- # If skip_progress is True, we modify the behavior of the model download process
39
  if skip_progress:
40
- # Manually set the file paths for the config and weights files if needed
41
- model_config = 'path_to_config.cfg' # Provide the correct path to config file
42
- model_weights = 'path_to_weights.weights' # Provide the correct path to weights file
43
  else:
44
- model_config = cv.download_file(url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.cfg", file_name="yolov3.cfg", dest_dir=".")
45
- model_weights = cv.download_file(url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.weights", file_name="yolov3.weights", dest_dir=".")
 
 
 
 
 
 
 
 
 
46
 
47
- # Run detection
48
  box, label, count = cv.detect_common_objects(image, model=model)
49
  return box, label, count
50
 
 
5
  from PIL import Image
6
  from collections import Counter
7
  import os
8
+ import requests
9
 
10
  # Streamlit app title
11
  st.set_page_config(page_title="Object Detection App", page_icon="🖼️", layout="centered")
 
22
  st.markdown("### Step 1: Upload an Image for Object Detection")
23
  uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
24
 
25
+ # Function to download a file without using the progress bar
26
+ def download_file_no_progress(url, file_name, dest_dir):
 
 
 
27
  file_path = os.path.join(dest_dir, file_name)
28
  if not os.path.exists(file_path):
 
29
  print(f"Downloading {file_name}...")
30
+ # Disable the progress bar by using requests
31
+ response = requests.get(url, stream=True)
32
+ with open(file_path, 'wb') as f:
33
+ for chunk in response.iter_content(chunk_size=1024):
34
+ if chunk:
35
+ f.write(chunk)
36
  return file_path
37
 
38
+ # Function to perform object detection with manual model file paths
39
  def detect_common_objects_skip_progress(image, model='yolov3', skip_progress=False):
 
40
  if skip_progress:
41
+ # Manually set paths for config and weights if progress bar should be disabled
42
+ model_config = 'path_to_config.cfg' # Provide the path to the .cfg file
43
+ model_weights = 'path_to_weights.weights' # Provide the path to the .weights file
44
  else:
45
+ # Download the config and weights files if not already present
46
+ model_config = download_file_no_progress(
47
+ url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.cfg",
48
+ file_name="yolov3.cfg",
49
+ dest_dir="."
50
+ )
51
+ model_weights = download_file_no_progress(
52
+ url="https://github.com/opencv/opencv_contrib/blob/master/modules/dnn/data/yolov3.weights",
53
+ file_name="yolov3.weights",
54
+ dest_dir="."
55
+ )
56
 
57
+ # Run the object detection
58
  box, label, count = cv.detect_common_objects(image, model=model)
59
  return box, label, count
60