GwFirman commited on
Commit
1927bd2
·
verified ·
1 Parent(s): ce9d5f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -26,8 +26,7 @@ def process_video(video_path):
26
  fourcc = cv2.VideoWriter_fourcc(*"mp4v")
27
  out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
28
 
29
- total_person_count = 0
30
-
31
  while cap.isOpened():
32
  ret, frame = cap.read()
33
  if not ret:
@@ -41,7 +40,6 @@ def process_video(video_path):
41
  # Filter hanya label 'person'
42
  person_detections = [d for d in detections if names[int(d[-1])] == "person"]
43
  person_count = len(person_detections)
44
- total_person_count += person_count
45
 
46
  # Render frame dan buat salinan eksplisit
47
  annotated_frame = results.render()[0]
@@ -58,20 +56,21 @@ def process_video(video_path):
58
  cap.release()
59
  out.release()
60
 
61
- return output_path, total_person_count
 
62
 
63
  # Fungsi Gradio untuk antarmuka
64
  def gradio_interface(video_file):
65
- output_path, total_person_count = process_video(video_file)
66
- return output_path, f"Total people detected: {total_person_count}"
67
 
68
  # Antarmuka Gradio
69
  iface = gr.Interface(
70
  fn=gradio_interface,
71
  inputs=gr.File(type="filepath"), # Input berupa file video
72
- outputs=[gr.File(label="Processed Video"), gr.Text(label="Total People Count")],
73
  title="Person Counter using YOLOv5",
74
- description="Upload a video file to detect and count the number of people using YOLOv5."
75
  )
76
 
77
  # Menjalankan aplikasi
 
26
  fourcc = cv2.VideoWriter_fourcc(*"mp4v")
27
  out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
28
 
29
+ # Proses video
 
30
  while cap.isOpened():
31
  ret, frame = cap.read()
32
  if not ret:
 
40
  # Filter hanya label 'person'
41
  person_detections = [d for d in detections if names[int(d[-1])] == "person"]
42
  person_count = len(person_detections)
 
43
 
44
  # Render frame dan buat salinan eksplisit
45
  annotated_frame = results.render()[0]
 
56
  cap.release()
57
  out.release()
58
 
59
+ # Mengembalikan video yang telah diproses (tidak menjumlahkan seluruh frame)
60
+ return output_path
61
 
62
  # Fungsi Gradio untuk antarmuka
63
  def gradio_interface(video_file):
64
+ output_path = process_video(video_file)
65
+ return output_path
66
 
67
  # Antarmuka Gradio
68
  iface = gr.Interface(
69
  fn=gradio_interface,
70
  inputs=gr.File(type="filepath"), # Input berupa file video
71
+ outputs=gr.File(label="Processed Video"),
72
  title="Person Counter using YOLOv5",
73
+ description="Upload a video file to detect and count the number of people in each frame using YOLOv5."
74
  )
75
 
76
  # Menjalankan aplikasi