prithivMLmods commited on
Commit
284b710
·
verified ·
1 Parent(s): 8081540

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -99,11 +99,12 @@ def video_inference(video_file):
99
  # Button Toggle Function
100
  def toggle_button(has_result):
101
  """
102
- Returns button label and visibility states based on whether a result has been generated.
103
  """
104
  if has_result:
105
- return "Start Again", gr.Button(visible=True), gr.Button(visible=False)
106
- return "Start", gr.Button(visible=False), gr.Button(visible=True)
 
107
 
108
  # Build the Gradio App
109
  def build_app():
@@ -120,13 +121,13 @@ def build_app():
120
  with gr.Row():
121
  with gr.Column():
122
  video = gr.Video(
123
- source="webcam",
124
  label="Webcam Recording",
125
  format="mp4"
126
  )
127
  # Two buttons: one for Start, one for Start Again
128
- start_again_btn = gr.Button("Start Again", visible=False)
129
  start_btn = gr.Button("Start", visible=True)
 
130
  with gr.Column():
131
  output_text = gr.Textbox(label="Model Output")
132
 
@@ -147,7 +148,7 @@ def build_app():
147
  has_result.change(
148
  fn=toggle_button,
149
  inputs=has_result,
150
- outputs=[start_again_btn, start_again_btn, start_btn]
151
  )
152
 
153
  # Clicking either button resets the video and output
 
99
  # Button Toggle Function
100
  def toggle_button(has_result):
101
  """
102
+ Returns visibility states for start_again_btn and start_btn based on has_result.
103
  """
104
  if has_result:
105
+ return gr.update(visible=True), gr.update(visible=False)
106
+ else:
107
+ return gr.update(visible=False), gr.update(visible=True)
108
 
109
  # Build the Gradio App
110
  def build_app():
 
121
  with gr.Row():
122
  with gr.Column():
123
  video = gr.Video(
124
+ sources=["webcam"],
125
  label="Webcam Recording",
126
  format="mp4"
127
  )
128
  # Two buttons: one for Start, one for Start Again
 
129
  start_btn = gr.Button("Start", visible=True)
130
+ start_again_btn = gr.Button("Start Again", visible=False)
131
  with gr.Column():
132
  output_text = gr.Textbox(label="Model Output")
133
 
 
148
  has_result.change(
149
  fn=toggle_button,
150
  inputs=has_result,
151
+ outputs=[start_again_btn, start_btn]
152
  )
153
 
154
  # Clicking either button resets the video and output