TheKnight115 commited on
Commit
abdcbed
·
verified ·
1 Parent(s): c578959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  from ultralytics import YOLO
5
 
6
  # Load the YOLO model
7
- model = YOLO('yolov8_motorbikes_detection_s.pt') # Ensure the model file is in the root directory of your Space
8
 
9
  def run_yolo(image):
10
  # Run the model on the image and get results
@@ -69,7 +69,8 @@ def process_video(uploaded_file):
69
 
70
  # Create a video writer to save the processed frames
71
  height, width, _ = frames[0].shape
72
- out = cv2.VideoWriter('processed_video.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 30, (width, height))
 
73
 
74
  for frame in frames:
75
  out.write(frame) # Write each processed frame to the video
@@ -80,7 +81,13 @@ def process_video(uploaded_file):
80
  progress_bar.progress(100)
81
  progress_text.text('Processing: 100%')
82
  st.success('Video processing complete!')
83
-
 
 
 
 
 
 
84
 
85
  def main():
86
  st.title("Motorbike Violation Detection")
@@ -103,7 +110,7 @@ def main():
103
  elif uploaded_file.type == "video/mp4":
104
  # Process the video
105
  process_video(uploaded_file) # Process the video and save the output
106
- st.video('processed_video.mp4') # Display the processed video
107
 
108
  if __name__ == "__main__":
109
  main()
 
4
  from ultralytics import YOLO
5
 
6
  # Load the YOLO model
7
+ model = YOLO('yolov8_Medium.pt') # Ensure the model file is in the root directory of your Space
8
 
9
  def run_yolo(image):
10
  # Run the model on the image and get results
 
69
 
70
  # Create a video writer to save the processed frames
71
  height, width, _ = frames[0].shape
72
+ output_path = 'processed_video.mp4'
73
+ out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'mp4v'), 30, (width, height))
74
 
75
  for frame in frames:
76
  out.write(frame) # Write each processed frame to the video
 
81
  progress_bar.progress(100)
82
  progress_text.text('Processing: 100%')
83
  st.success('Video processing complete!')
84
+
85
+ st.video(output_path) # Display the processed video
86
+
87
+ # Create a download button for the processed video
88
+ with open(output_path, 'rb') as f:
89
+ video_bytes = f.read()
90
+ st.download_button(label='Download Processed Video', data=video_bytes, file_name='processed_video.mp4', mime='video/mp4')
91
 
92
  def main():
93
  st.title("Motorbike Violation Detection")
 
110
  elif uploaded_file.type == "video/mp4":
111
  # Process the video
112
  process_video(uploaded_file) # Process the video and save the output
113
+
114
 
115
  if __name__ == "__main__":
116
  main()