rosebe commited on
Commit
668d89d
·
1 Parent(s): 5b85a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -20,10 +20,6 @@
20
 
21
  # if __name__ == "__main__":
22
  # demo.launch()
23
-
24
- import gradio as gr
25
- import torch
26
- import cv2
27
  # from IPython.display import clear_output
28
  # import os, urllib.request
29
  # import subprocess
@@ -126,33 +122,37 @@ import cv2
126
  # print('Installation finished.')
127
 
128
  # Define the face detector function
 
 
 
 
 
 
 
 
 
 
129
  def detect_image(image):
130
  results = model(image)
131
-
132
  return results.render()[0]
133
-
134
- def detect_video(video_path):
135
 
 
136
  video = cv2.VideoCapture(video_path)
137
-
138
  frame_count = 0
139
  while True:
140
-
141
  success, frame = video.read()
142
  if not success:
143
  break
144
- frame = model.predict();
145
  frame_output_path = f'frame_{frame_count}.jpg' # Replace with your desired output path
146
  cv2.imwrite(frame_output_path, frame)
147
-
148
  frame_count += 1
149
-
150
  video.release()
151
  cv2.destroyAllWindows()
152
 
153
- frame_rate = 30 # Adjust as needed
154
 
155
- image_dir = 'path_to_image_directory' # Replace with the directory containing the image files
156
  image_files = sorted(os.listdir(image_dir))
157
 
158
  image_path = os.path.join(image_dir, image_files[0])
@@ -185,7 +185,6 @@ vid_interface = gr.Interface(
185
  outputs="video",
186
  title="Video"
187
  )
188
-
189
  # Create a list of interfaces
190
  interfaces = [img_interface, vid_interface]
191
 
 
20
 
21
  # if __name__ == "__main__":
22
  # demo.launch()
 
 
 
 
23
  # from IPython.display import clear_output
24
  # import os, urllib.request
25
  # import subprocess
 
122
  # print('Installation finished.')
123
 
124
  # Define the face detector function
125
+
126
+
127
+ import gradio as gr
128
+ import torch
129
+ import cv2
130
+ import os
131
+
132
+ # Load the model
133
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
134
+
135
  def detect_image(image):
136
  results = model(image)
 
137
  return results.render()[0]
 
 
138
 
139
+ def detect_video(video_path):
140
  video = cv2.VideoCapture(video_path)
 
141
  frame_count = 0
142
  while True:
 
143
  success, frame = video.read()
144
  if not success:
145
  break
146
+ frame = model(frame)[0].numpy().astype('uint8')
147
  frame_output_path = f'frame_{frame_count}.jpg' # Replace with your desired output path
148
  cv2.imwrite(frame_output_path, frame)
 
149
  frame_count += 1
 
150
  video.release()
151
  cv2.destroyAllWindows()
152
 
153
+ frame_rate = video.get(cv2.CAP_PROP_FPS)
154
 
155
+ image_dir = '.' # Replace with the directory containing the image files (frames)
156
  image_files = sorted(os.listdir(image_dir))
157
 
158
  image_path = os.path.join(image_dir, image_files[0])
 
185
  outputs="video",
186
  title="Video"
187
  )
 
188
  # Create a list of interfaces
189
  interfaces = [img_interface, vid_interface]
190