Medha Sawhney commited on
Commit
53aaa4a
·
1 Parent(s): c429c7f

Adding support for multiple inputs, resolved output errors

Browse files
Files changed (1) hide show
  1. app.py +74 -30
app.py CHANGED
@@ -81,7 +81,7 @@ def download_and_unzip_google_drive_file(file_id, output_path, unzip_path):
81
 
82
 
83
  # @spaces.GPU()
84
- def doo(video, fps, min_track_length, progress=gr.Progress()):
85
  # download and unzip models
86
  # file_id = '1agsLD5HV_VmDNpDhjHXTCAVmGUm2IQ6p'
87
  # output_path = 'models.zip'
@@ -161,47 +161,91 @@ def doo(video, fps, min_track_length, progress=gr.Progress()):
161
  progress(2 / 3, desc=f"Tracking {2}/{3}")
162
  folder_path = analyse_tracking(video_num=video_num, min_track_length=min_track_length, data_feature_path=feature_data_path, data_root_path=final_data_dir, plot=True)
163
  progress(3 / 3, desc=f"Tracking {3}/{3}")
164
- output_video = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path)
165
- final_video = os.path.basename(output_video)
166
- shutil.copy(output_video, final_video)
167
- print(output_video)
168
- print(final_video)
 
 
169
 
170
  search_pattern = "TrackedRawData"
171
  tracking_preds = find_and_return_csv_files(folder_path, search_pattern)
172
 
173
 
174
- return final_video, tracking_preds
175
 
176
 
177
- examples = [['RBS_2_4_h264.mp4'], ['RBS_4_4_h264.mp4']]# ['RBS_7_6_h264.mp4']]
178
 
179
- title = "🎞️ MEMTrack Bacteria Tracking Video Tool"
180
- description = "Upload a video or selct from example to track. <br><br> If the input video does not play on browser, ensure its in a browser accetable format. Output will be generated iirespective of playback on browser. Refer: https://colab.research.google.com/drive/1U5pX_9iaR_T8knVV7o4ftKdDoGndCdEM?usp=sharing"
181
 
 
182
 
183
- inputs = [
184
- gr.Video(label="Input Video"),
185
- gr.Slider(minimum=1, maximum=100, step=1, default=60, label="FPS", choices=[10, 20, 30, 60]),
186
- gr.Slider(minimum=1, maximum=1000, step=1, default=60, label="Minimum Track Length Threshold", choices=[5, 10, 20, 50, 100])
187
- ]
188
 
189
- outputs = [
190
- gr.Video(label="Tracked Video"),
191
- gr.Files(label="CSV Data")
192
- ]
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
- iface = gr.Interface(
196
- fn=doo,
197
- inputs=inputs,
198
- outputs=outputs,
199
- examples=examples,
200
- title=title,
201
- description=description,
202
- cache_examples=True,
203
- )
204
 
205
 
206
- if __name__ == "__main__":
207
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
 
83
  # @spaces.GPU()
84
+ def doo(video, tiff_stack, images, fps, min_track_length, progress=gr.Progress()):
85
  # download and unzip models
86
  # file_id = '1agsLD5HV_VmDNpDhjHXTCAVmGUm2IQ6p'
87
  # output_path = 'models.zip'
 
161
  progress(2 / 3, desc=f"Tracking {2}/{3}")
162
  folder_path = analyse_tracking(video_num=video_num, min_track_length=min_track_length, data_feature_path=feature_data_path, data_root_path=final_data_dir, plot=True)
163
  progress(3 / 3, desc=f"Tracking {3}/{3}")
164
+ output_video1 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path)
165
+ output_video2 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path, all_images=True)
166
+ final_videos = [os.path.basename(output_video1), os.path.basename(output_video2)]
167
+ shutil.copy(output_video1, final_videos[0])
168
+ shutil.copy(output_video2, final_videos[1])
169
+ print(output_video1)
170
+ print(final_videos)
171
 
172
  search_pattern = "TrackedRawData"
173
  tracking_preds = find_and_return_csv_files(folder_path, search_pattern)
174
 
175
 
176
+ return final_video[0], final_video[1], tracking_preds
177
 
178
 
 
179
 
 
 
180
 
181
+ if __name__ == "__main__":
182
 
183
+ examples = [['RBS_2_4_h264.mp4'], ['RBS_4_4_h264.mp4'], ['RBS_7_6_h264.mp4']]
184
+
185
+ title = "🎞️ MEMTrack Bacteria Tracking Video Tool"
186
+ description = "Upload a video or selct from example to track. <br><br> If the input video does not play on browser, ensure its in a browser accetable format. Output will be generated iirespective of playback on browser. Refer: https://colab.research.google.com/drive/1U5pX_9iaR_T8knVV7o4ftKdDoGndCdEM?usp=sharing"
 
187
 
 
 
 
 
188
 
189
+ with gr.Blocks() as demo:
190
+ gr.Markdown(f"# {title}")
191
+ gr.Markdown(description)
192
+
193
+ with gr.Row():
194
+ with gr.Column():
195
+ gr.Markdown("Select the appropriate tab to upload a video, a TIFF stack, or a folder containing image frames.")
196
+
197
+ with gr.Tabs():
198
+ with gr.Tab("Upload Video"):
199
+ video_input = gr.Video(label="Video File")
200
+
201
+ with gr.Tab("Upload TIFF Stack"):
202
+ tiff_input = gr.File(label="TIFF File", file_types=["tif", "tiff"])
203
+
204
+ with gr.Tab("Upload Images"):
205
+ image_input = gr.File(label="Image Files", file_types=["jpg", "jpeg", "png", "tif", "tiff"], file_count="multiple")
206
+
207
+ # Common sliders for all inputs
208
+ fps_slider = gr.Slider(minimum=1, maximum=100, step=1, value=60, label="Output Video FPS")
209
+ track_length_slider = gr.Slider(minimum=0, maximum=1000, step=1, value=60, label="Minimum Track Length Threshold")
210
+ with gr.Column():
211
+ outputs = [
212
+ gr.Video(label="Tracked Video (tracked frames)"),
213
+ gr.Video(label="Tracked Video (all frames)"),
214
+ gr.Files(label="CSV Data")
215
+ ]
216
+
217
+
218
+ submit_button = gr.Button("Process Input")
219
+ submit_button.click(
220
+ fn=doo,
221
+ inputs=[video_input, tiff_input, image_input, fps_slider, track_length_slider],
222
+ outputs=outputs
223
+ )
224
+
225
+ demo.launch(share=True, debug=True)
226
 
 
 
 
 
 
 
 
 
 
227
 
228
 
229
+
230
+
231
+
232
+
233
+ # inputs = [
234
+ # gr.Video(label="Input Video"),
235
+ # gr.Slider(minimum=1, maximum=100, step=1, value=60, label="Output Video FPS" ),
236
+ # gr.Slider(minimum=0, maximum=1000, step=1, value=60, label="Minimum Track Length Threshold")
237
+ # ]
238
+
239
+
240
+ # iface = gr.Interface(
241
+ # fn=doo,
242
+ # inputs=inputs,
243
+ # outputs=outputs,
244
+ # examples=examples,
245
+ # title=title,
246
+ # description=description,
247
+ # cache_examples=False,
248
+ # )
249
+
250
+ # if __name__ == "__main__":
251
+ # iface.launch(share=True, debug=True)