Spaces:
Runtime error
Runtime error
Commit ·
c780404
1
Parent(s): 592e4db
Video codec testing
Browse files- app.py +33 -12
- state_handler.py +1 -0
- static/test.mp4 +0 -0
app.py
CHANGED
|
@@ -110,6 +110,7 @@ def handle_next(_, progress=gr.Progress()):
|
|
| 110 |
|
| 111 |
# Store result for that file
|
| 112 |
result['json_result'].append(json_result)
|
|
|
|
| 113 |
result["path_video"].append(video_filepath)
|
| 114 |
result["path_zip"].append(zip_filepath)
|
| 115 |
result["path_json"].append(json_filepath)
|
|
@@ -148,15 +149,17 @@ def show_data():
|
|
| 148 |
not_done = state['index'] < state['total']
|
| 149 |
|
| 150 |
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
annotation_html = "<div style='display:flex'>"
|
| 155 |
-
annotation_html += "<canvas id='canvas' style='width:50%' onmousedown='mouse_down(event)' onmousemove='mouse_move(event)' onmouseup='mouse_up()' onmouseleave='mouse_up()'></canvas>"
|
| 156 |
-
annotation_html += "<div id='annotation_display' style='width:50%'></div>"
|
| 157 |
-
annotation_html += "</div>"
|
| 158 |
-
annotation_html += "<p id='annotation_info' style='display:none'>" + json.dumps(frame_info) + "</p>"
|
| 159 |
-
annotation_html += "<img id='annotation_img' onload='draw()' style='display:none'></img>"
|
| 160 |
|
| 161 |
# Send update to UI, and to inference_handler to start next file inference
|
| 162 |
return {
|
|
@@ -172,11 +175,24 @@ def show_data():
|
|
| 172 |
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
def preview_result(zip_info):
|
| 177 |
zip_name = zip_info[0]
|
| 178 |
print(zip_name)
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
with ZipFile(zip_name) as zip_file:
|
| 181 |
ZipFile.extractall(zip_file, path=dir_name)
|
| 182 |
|
|
@@ -193,9 +209,10 @@ def preview_result(zip_info):
|
|
| 193 |
elif (file.endswith("_marking.txt")):
|
| 194 |
result["path_marking"].append(os.path.join(dir_name, file))
|
| 195 |
|
|
|
|
| 196 |
with open(result['path_json'][0]) as f:
|
| 197 |
json_result = json.load(f)
|
| 198 |
-
result['json_result']
|
| 199 |
fish_table, fish_info = create_metadata_table(json_result, table_headers, info_headers)
|
| 200 |
result["fish_table"].append(fish_table)
|
| 201 |
result["fish_info"].append(fish_info)
|
|
@@ -236,8 +253,12 @@ with demo:
|
|
| 236 |
|
| 237 |
with gr.Tab("Review Results"):
|
| 238 |
# Title of page
|
| 239 |
-
gr.HTML("
|
|
|
|
|
|
|
|
|
|
| 240 |
result_input = File(file_types=[".zip"], type="binary", label="Upload result file")
|
|
|
|
| 241 |
preview_result_btn = gr.Button("Preview Result")
|
| 242 |
|
| 243 |
|
|
@@ -295,7 +316,7 @@ with demo:
|
|
| 295 |
result_handler.change(show_data, None, UI_components + [inference_handler], _js=js_update_tabs)
|
| 296 |
|
| 297 |
# Button to load a previous result and view visualization
|
| 298 |
-
preview_result_btn.click(preview_result, result_input, [result_handler, inference_handler])
|
| 299 |
|
| 300 |
demo.queue().launch()
|
| 301 |
|
|
|
|
| 110 |
|
| 111 |
# Store result for that file
|
| 112 |
result['json_result'].append(json_result)
|
| 113 |
+
result['aris_input'].append(file_path)
|
| 114 |
result["path_video"].append(video_filepath)
|
| 115 |
result["path_zip"].append(zip_filepath)
|
| 116 |
result["path_json"].append(json_filepath)
|
|
|
|
| 149 |
not_done = state['index'] < state['total']
|
| 150 |
|
| 151 |
|
| 152 |
+
annotation_html = ""
|
| 153 |
+
if result["aris_input"][i]:
|
| 154 |
+
frame_info = load_frames(result["aris_input"][i], result['json_result'][i])
|
| 155 |
|
| 156 |
+
annotation_html = "<div style='display:flex'>"
|
| 157 |
+
annotation_html += "<canvas id='canvas' style='width:50%' onmousedown='mouse_down(event)' onmousemove='mouse_move(event)' onmouseup='mouse_up()' onmouseleave='mouse_up()'></canvas>"
|
| 158 |
+
annotation_html += "<div id='annotation_display' style='width:50%'></div>"
|
| 159 |
+
annotation_html += "</div>"
|
| 160 |
+
annotation_html += "<p id='annotation_info' style='display:none'>" + json.dumps(frame_info) + "</p>"
|
| 161 |
+
annotation_html += "<img id='annotation_img' onload='draw()' style='display:none'></img>"
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
# Send update to UI, and to inference_handler to start next file inference
|
| 165 |
return {
|
|
|
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
+
def testing():
|
| 179 |
+
codec = cv2.VideoWriter_fourcc(*'avc1')
|
| 180 |
+
cv2.VideoWriter("static/test.mp4", codec, 10, [ int(1.5*100), 100 ] )
|
| 181 |
+
print("hi")
|
| 182 |
+
testing()
|
| 183 |
|
| 184 |
+
def preview_result(zip_info, aris_info):
|
| 185 |
zip_name = zip_info[0]
|
| 186 |
print(zip_name)
|
| 187 |
+
if (aris_info):
|
| 188 |
+
print(aris_info[0])
|
| 189 |
+
file_name = aris_info[0].split("/")[-1]
|
| 190 |
+
bytes = aris_info[1]
|
| 191 |
+
valid, file_path, dir_name = save_data(bytes, file_name)
|
| 192 |
+
else:
|
| 193 |
+
dir_name = create_data_dir()
|
| 194 |
+
file_path = None
|
| 195 |
+
|
| 196 |
with ZipFile(zip_name) as zip_file:
|
| 197 |
ZipFile.extractall(zip_file, path=dir_name)
|
| 198 |
|
|
|
|
| 209 |
elif (file.endswith("_marking.txt")):
|
| 210 |
result["path_marking"].append(os.path.join(dir_name, file))
|
| 211 |
|
| 212 |
+
result["aris_input"].append(file_path)
|
| 213 |
with open(result['path_json'][0]) as f:
|
| 214 |
json_result = json.load(f)
|
| 215 |
+
result['json_result'].append(json_result)
|
| 216 |
fish_table, fish_info = create_metadata_table(json_result, table_headers, info_headers)
|
| 217 |
result["fish_table"].append(fish_table)
|
| 218 |
result["fish_info"].append(fish_info)
|
|
|
|
| 253 |
|
| 254 |
with gr.Tab("Review Results"):
|
| 255 |
# Title of page
|
| 256 |
+
gr.HTML("""
|
| 257 |
+
<p align='center' style='font-size: large;font-style: italic;'>Submit an old zip file of results to visualize.</p>
|
| 258 |
+
<p align='center' style='font-size: large;font-style: italic;'>If you want to edit annotations, also submit an aris file.</p>
|
| 259 |
+
""")
|
| 260 |
result_input = File(file_types=[".zip"], type="binary", label="Upload result file")
|
| 261 |
+
result_aris_input = File(file_types=[".aris", ".ddf"], type="binary", label="Upload aris file (optional)")
|
| 262 |
preview_result_btn = gr.Button("Preview Result")
|
| 263 |
|
| 264 |
|
|
|
|
| 316 |
result_handler.change(show_data, None, UI_components + [inference_handler], _js=js_update_tabs)
|
| 317 |
|
| 318 |
# Button to load a previous result and view visualization
|
| 319 |
+
preview_result_btn.click(preview_result, [result_input, result_aris_input], [result_handler, inference_handler, preview_result_btn])
|
| 320 |
|
| 321 |
demo.queue().launch()
|
| 322 |
|
state_handler.py
CHANGED
|
@@ -364,6 +364,7 @@ def reset_state(result, state):
|
|
| 364 |
|
| 365 |
# Reset Result
|
| 366 |
result["json_result"] = []
|
|
|
|
| 367 |
result["path_video"] = []
|
| 368 |
result["path_zip"] = []
|
| 369 |
result["path_json"] = []
|
|
|
|
| 364 |
|
| 365 |
# Reset Result
|
| 366 |
result["json_result"] = []
|
| 367 |
+
result["aris_input"] = []
|
| 368 |
result["path_video"] = []
|
| 369 |
result["path_zip"] = []
|
| 370 |
result["path_json"] = []
|
static/test.mp4
ADDED
|
Binary file (262 Bytes). View file
|
|
|