reab5555 commited on
Commit
0c3c81c
·
verified ·
1 Parent(s): 18d311d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -59,18 +59,18 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
59
  return [error_message] + [None] * 27
60
 
61
  def show_results():
62
- return [gr.Tab.update(visible=True) for _ in range(4)] + [gr.Tab.update(visible=False)]
63
-
64
- def hide_description_show_results():
65
- return [gr.Tab.update(visible=False)] + [gr.Tab.update(visible=True) for _ in range(4)], gr.Group.update(visible=True)
66
 
67
  def start_execution_timer():
68
- return gr.Number.update(value=0, visible=True), gr.Markdown.update(visible=True)
69
 
70
  def update_execution_time():
71
- return gr.Number.update()
 
72
 
73
  with gr.Blocks() as iface:
 
 
74
  with gr.Row():
75
  video_input = gr.Video(label="Input Video")
76
 
@@ -78,16 +78,11 @@ with gr.Blocks() as iface:
78
  fps_slider = gr.Slider(minimum=5, maximum=20, step=1, value=10, label="Frames Per Second (FPS)")
79
  process_btn = gr.Button("Detect Anomalies")
80
  progress_bar = gr.Progress()
81
-
82
- execution_time_group = gr.Group(visible=False)
83
- with execution_time_group:
84
- execution_time = gr.Number(label="Execution Time", visible=False)
85
- execution_time_text = gr.Markdown("Execution time will be displayed here", visible=False)
86
 
87
  with gr.Tabs() as all_tabs:
88
  description_tab = gr.Tab("Description")
89
  with description_tab:
90
- gr.Markdown("""
91
  # Multimodal Behavioral Anomalies Detection
92
 
93
  This tool detects anomalies in facial expressions, body language, and voice over the timeline of a video.
@@ -133,18 +128,18 @@ with gr.Blocks() as iface:
133
  mse_heatmap_voice_store = gr.State()
134
 
135
  process_btn.click(
136
- start_execution_timer,
137
  inputs=None,
138
- outputs=[execution_time, execution_time_text]
139
  ).then(
140
- hide_description_show_results,
141
  inputs=None,
142
- outputs=[description_tab, facial_features_tab, body_posture_tab, voice_tab, combined_tab, execution_time_group]
143
  ).then(
144
  process_and_show_completion,
145
  inputs=[video_input, anomaly_threshold, fps_slider],
146
  outputs=[
147
- execution_time, results_text, df_store,
148
  mse_features_store, mse_posture_store, mse_voice_store,
149
  mse_features_plot, mse_posture_plot, mse_voice_plot,
150
  mse_features_hist, mse_posture_hist, mse_voice_hist,
@@ -158,13 +153,13 @@ with gr.Blocks() as iface:
158
  ).then(
159
  show_results,
160
  inputs=None,
161
- outputs=all_tabs.children
162
  )
163
 
164
- execution_time.change(
165
  update_execution_time,
166
- inputs=None,
167
- outputs=execution_time_text,
168
  every=1
169
  )
170
 
 
59
  return [error_message] + [None] * 27
60
 
61
  def show_results():
62
+ return [gr.Tab.update(visible=True) for _ in range(4)]
 
 
 
63
 
64
  def start_execution_timer():
65
+ return gr.Markdown.update(value="Execution time: 0 seconds", visible=True)
66
 
67
  def update_execution_time():
68
+ current_time = time.time() - start_time
69
+ return gr.Markdown.update(value=f"Execution time: {current_time:.2f} seconds")
70
 
71
  with gr.Blocks() as iface:
72
+ start_time = gr.State(0)
73
+
74
  with gr.Row():
75
  video_input = gr.Video(label="Input Video")
76
 
 
78
  fps_slider = gr.Slider(minimum=5, maximum=20, step=1, value=10, label="Frames Per Second (FPS)")
79
  process_btn = gr.Button("Detect Anomalies")
80
  progress_bar = gr.Progress()
 
 
 
 
 
81
 
82
  with gr.Tabs() as all_tabs:
83
  description_tab = gr.Tab("Description")
84
  with description_tab:
85
+ description_md = gr.Markdown("""
86
  # Multimodal Behavioral Anomalies Detection
87
 
88
  This tool detects anomalies in facial expressions, body language, and voice over the timeline of a video.
 
128
  mse_heatmap_voice_store = gr.State()
129
 
130
  process_btn.click(
131
+ lambda: time.time(),
132
  inputs=None,
133
+ outputs=start_time
134
  ).then(
135
+ start_execution_timer,
136
  inputs=None,
137
+ outputs=description_md
138
  ).then(
139
  process_and_show_completion,
140
  inputs=[video_input, anomaly_threshold, fps_slider],
141
  outputs=[
142
+ description_md, results_text, df_store,
143
  mse_features_store, mse_posture_store, mse_voice_store,
144
  mse_features_plot, mse_posture_plot, mse_voice_plot,
145
  mse_features_hist, mse_posture_hist, mse_voice_hist,
 
153
  ).then(
154
  show_results,
155
  inputs=None,
156
+ outputs=all_tabs.children[1:]
157
  )
158
 
159
+ description_md.change(
160
  update_execution_time,
161
+ inputs=[start_time],
162
+ outputs=description_md,
163
  every=1
164
  )
165