asif00 commited on
Commit
cfc42c6
·
1 Parent(s): abfdd6f
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -24,31 +24,32 @@ def process_frame(frame):
24
  segments = results[0].plot()
25
  return segments, f'FPS: {int(1 // (end - start))}'
26
 
27
- def process_inputs(start_button, stop_button, mode_selection, frame, uploaded_video):
28
  global process, model
29
- if start_button and mode_selection:
30
- process = True
31
- model = load_yolo_model()
32
  if mode_selection == "Webcam" and frame is not None:
 
 
33
  return process_frame(frame)
34
  elif mode_selection == "Video" and uploaded_video is not None:
 
 
35
  return process_frame(uploaded_video)
36
- elif stop_button:
37
  process = False
38
 
39
- start_button = gr.inputs.Button(label="Start")
40
- stop_button = gr.inputs.Button(label="Stop")
41
  mode_selection = gr.inputs.Radio(["Webcam", "Video"], label="Mode Selection")
42
  frame = gr.inputs.Video(shape=(720, 1280), label="Webcam Feed")
43
  uploaded_video = gr.inputs.Video(shape=(720, 1280), label="Upload Video")
44
 
45
  iface = gr.Interface(
46
  fn=process_inputs,
47
- inputs=[start_button, stop_button, mode_selection, frame, uploaded_video],
48
  outputs=[gr.outputs.Image(), gr.outputs.Textbox()],
49
  live=True,
50
  title="YOLO Image Segmentation",
51
- description="This application uses the YOLO model to perform image segmentation on a webcam feed or an uploaded video. Select 'Webcam' or 'Video', upload a video (if applicable), and click 'Start' to begin. Click 'Stop' to end the process.",
52
  theme="huggingface"
53
  )
54
 
 
24
  segments = results[0].plot()
25
  return segments, f'FPS: {int(1 // (end - start))}'
26
 
27
+ def process_inputs(action, mode_selection, frame, uploaded_video):
28
  global process, model
29
+ if action == "Start" and not process and mode_selection:
 
 
30
  if mode_selection == "Webcam" and frame is not None:
31
+ process = True
32
+ model = load_yolo_model()
33
  return process_frame(frame)
34
  elif mode_selection == "Video" and uploaded_video is not None:
35
+ process = True
36
+ model = load_yolo_model()
37
  return process_frame(uploaded_video)
38
+ elif action == "Stop" and process:
39
  process = False
40
 
41
+ action = gr.inputs.Dropdown(choices=["Start", "Stop"], label="Action")
 
42
  mode_selection = gr.inputs.Radio(["Webcam", "Video"], label="Mode Selection")
43
  frame = gr.inputs.Video(shape=(720, 1280), label="Webcam Feed")
44
  uploaded_video = gr.inputs.Video(shape=(720, 1280), label="Upload Video")
45
 
46
  iface = gr.Interface(
47
  fn=process_inputs,
48
+ inputs=[action, mode_selection, frame, uploaded_video],
49
  outputs=[gr.outputs.Image(), gr.outputs.Textbox()],
50
  live=True,
51
  title="YOLO Image Segmentation",
52
+ description="This application uses the YOLO model to perform image segmentation on a webcam feed or an uploaded video. Select 'Webcam' or 'Video', upload a video (if applicable), and select 'Start' to begin. Select 'Stop' to end the process.",
53
  theme="huggingface"
54
  )
55