randomshit11 commited on
Commit
91b37a6
·
verified ·
1 Parent(s): 0b9ee17

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -69
main.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
- from ultralytics.solutions import ai_gym
4
  import cv2
5
 
6
  def process(video_path):
@@ -27,7 +27,7 @@ def process(video_path):
27
  print("Video processing has been successfully completed.")
28
  break
29
  frame_count += 1
30
- results = model.track(im0, verbose=False) # Tracking recommended
31
  im0 = gym_object.start_counting(im0, results, frame_count)
32
  video_writer.write(im0)
33
 
@@ -41,15 +41,16 @@ title = "Push-up Counter"
41
  description = "This app counts the number of push-ups in a video."
42
  # inputs = gr.inputs.Video(label='Input Video')
43
  # outputs = gr.outputs.Video(label='Processed Video')
44
- # example_list = ['pullups.mp4']
45
 
46
  # Create the Gradio demo
47
  demo = gr.Interface(fn=process,
48
  inputs=gr.Video(label='Input Video'),
49
  outputs=gr.Video(label='Output Video')
50
- # title=title,
51
- # description=description,
52
- # examples=example_list
 
53
  )
54
 
55
  # Launch the demo!
@@ -60,66 +61,3 @@ demo.launch(show_api=True)
60
 
61
 
62
 
63
-
64
-
65
- # import gradio as gr
66
- # from ultralytics import YOLO
67
- # from ultralytics.solutions import ai_gym
68
- # import cv2
69
- # import tempfile
70
- # from PIL import Image
71
- # import subprocess
72
-
73
- # # Function to upgrade pip
74
- # def upgrade_pip():
75
- # subprocess.run(['pip', 'install', '--upgrade', 'pip'])
76
-
77
- # # Function to process video
78
- # def process(video_path):
79
- # upgrade_pip() # Upgrade pip before executing the main function
80
- # model = YOLO("yolov8n-pose.pt")
81
- # cap = cv2.VideoCapture(video_path)
82
- # assert cap.isOpened(), "Error reading video file"
83
- # w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
84
-
85
- # temp_dir = tempfile.mkdtemp() # Create a temporary directory to store processed frames
86
- # video_writer = cv2.VideoWriter("output_video.mp4",
87
- # cv2.VideoWriter_fourcc(*'mp4v'),
88
- # fps,
89
- # (w, h))
90
-
91
- # gym_object = ai_gym.AIGym() # init AI GYM module
92
- # gym_object.set_args(line_thickness=2,
93
- # view_img=False, # Set view_img to False to prevent displaying the video in real-time
94
- # pose_type="pushup",
95
- # kpts_to_check=[6, 8, 10])
96
-
97
- # frame_count = 0
98
- # while cap.isOpened():
99
- # success, im0 = cap.read()
100
- # if not success:
101
- # print("Video frame is empty or video processing has been successfully completed.")
102
- # break
103
- # frame_count += 1
104
- # if frame_count % 5 == 0: # Process every 5th frame
105
- # results = model.track(im0, verbose=False) # Tracking recommended
106
- # im0 = gym_object.start_counting(im0, results, frame_count)
107
- # # Save processed frame as an image in the temporary directory
108
- # cv2.imwrite(f"{temp_dir}/{frame_count}.jpg", im0)
109
-
110
- # # Use PIL to create the final video from the processed frames
111
- # images = [Image.open(f"{temp_dir}/{i}.jpg") for i in range(1, frame_count + 1)]
112
- # images[0].save("output_video.mp4", save_all=True, append_images=images[1:], duration=1000/fps, loop=0)
113
-
114
- # cap.release()
115
- # cv2.destroyAllWindows()
116
-
117
- # return "output_video.mp4"
118
-
119
- # # Create the Gradio demo
120
- # demo = gr.Interface(fn=process,
121
- # inputs=gr.Video(label='Input Video'),
122
- # outputs=gr.Video(label='Processed Video'))
123
-
124
- # # Launch the demo!
125
- # demo.launch(show_api=False)
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
+ import ai_gym
4
  import cv2
5
 
6
  def process(video_path):
 
27
  print("Video processing has been successfully completed.")
28
  break
29
  frame_count += 1
30
+ results = model.track(im0, verbose=True) # Tracking recommended
31
  im0 = gym_object.start_counting(im0, results, frame_count)
32
  video_writer.write(im0)
33
 
 
41
  description = "This app counts the number of push-ups in a video."
42
  # inputs = gr.inputs.Video(label='Input Video')
43
  # outputs = gr.outputs.Video(label='Processed Video')
44
+ example_list = ['Examples/PULL-UPS.mp4','Examples/PUSH-UPS.mp4']
45
 
46
  # Create the Gradio demo
47
  demo = gr.Interface(fn=process,
48
  inputs=gr.Video(label='Input Video'),
49
  outputs=gr.Video(label='Output Video')
50
+ title=title,
51
+ description=description,
52
+ examples=example_list,
53
+ cache_examples=True,
54
  )
55
 
56
  # Launch the demo!
 
61
 
62
 
63