Spaces:
Running
Running
Commit
·
9126ac5
1
Parent(s):
b221fea
update
Browse files
app.py
CHANGED
@@ -266,8 +266,6 @@ with gr.Blocks() as demo:
|
|
266 |
("IC-U-Net", "ICUNet"),
|
267 |
("IC-U-Net++", "UNetpp"),
|
268 |
("IC-U-Net-Attn", "AttUnet")],
|
269 |
-
#"(mapped data)",
|
270 |
-
#"(denoised data)"],
|
271 |
value="EEGART",
|
272 |
label="Model")
|
273 |
run_btn = gr.Button("Run", interactive=False)
|
@@ -302,7 +300,6 @@ with gr.Blocks() as demo:
|
|
302 |
os.mkdir(rootpath+"/session_data/")
|
303 |
#print(e)
|
304 |
os.mkdir(rootpath+"/session_data/stage1/")
|
305 |
-
os.mkdir(rootpath+"/session_data/stage2/")
|
306 |
|
307 |
# initialize channel_info, app_info
|
308 |
channel_info = {}
|
@@ -329,11 +326,12 @@ with gr.Blocks() as demo:
|
|
329 |
]
|
330 |
},
|
331 |
"stage2" : {
|
332 |
-
"filePath" :
|
333 |
"fileNames" : {
|
334 |
"input_data" : "",
|
335 |
"output_data" : ""
|
336 |
},
|
|
|
337 |
"totalBatchNum" : None,
|
338 |
"sampleRate" : None
|
339 |
}
|
@@ -815,9 +813,10 @@ with gr.Blocks() as demo:
|
|
815 |
# +========================================================================================+
|
816 |
# | Stage2: decode data |
|
817 |
# +========================================================================================+
|
|
|
818 |
@gr.on(triggers = [in_data_file.upload, in_data_file.clear, in_samplerate.change, out_json_file.change],
|
819 |
inputs = [app_info_json, in_data_file, in_samplerate], outputs = run_btn)
|
820 |
-
def
|
821 |
if app_info["stage1"]["state"]=="finished" and in_data!=None and samplerate!="":
|
822 |
return gr.Button(interactive=True)
|
823 |
else:
|
@@ -826,11 +825,11 @@ with gr.Blocks() as demo:
|
|
826 |
def reset_run(app_info, in_data, samplerate, modelname):
|
827 |
stage1_info = app_info["stage1"]
|
828 |
stage2_info = app_info["stage2"]
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
# establish a new folder
|
834 |
new_filepath = app_info["rootPath"]+"stage2_"+str(random.randint(1,10000))+"/"
|
835 |
os.mkdir(new_filepath)
|
836 |
# generate the output filename
|
@@ -843,6 +842,7 @@ with gr.Blocks() as demo:
|
|
843 |
"input_data" : in_data,
|
844 |
"output_data" : new_filepath + new_filename
|
845 |
},
|
|
|
846 |
"sampleRate" : int(samplerate)
|
847 |
})
|
848 |
app_info["stage2"] = stage2_info
|
@@ -899,7 +899,9 @@ with gr.Blocks() as demo:
|
|
899 |
yield {run_btn : gr.Button(visible=True),
|
900 |
cancel_btn : gr.Button(visible=False)}
|
901 |
else:
|
902 |
-
|
|
|
|
|
903 |
cancel_btn : gr.Button(visible=False),
|
904 |
batch_md : gr.Markdown(visible=False),
|
905 |
out_data_file : gr.File(new_filename, visible=True)}
|
@@ -916,7 +918,7 @@ with gr.Blocks() as demo:
|
|
916 |
).success(
|
917 |
fn = run_model,
|
918 |
inputs = [app_info_json, in_modelname],
|
919 |
-
outputs = [run_btn, cancel_btn, batch_md, out_data_file]
|
920 |
)
|
921 |
|
922 |
if __name__ == "__main__":
|
|
|
266 |
("IC-U-Net", "ICUNet"),
|
267 |
("IC-U-Net++", "UNetpp"),
|
268 |
("IC-U-Net-Attn", "AttUnet")],
|
|
|
|
|
269 |
value="EEGART",
|
270 |
label="Model")
|
271 |
run_btn = gr.Button("Run", interactive=False)
|
|
|
300 |
os.mkdir(rootpath+"/session_data/")
|
301 |
#print(e)
|
302 |
os.mkdir(rootpath+"/session_data/stage1/")
|
|
|
303 |
|
304 |
# initialize channel_info, app_info
|
305 |
channel_info = {}
|
|
|
326 |
]
|
327 |
},
|
328 |
"stage2" : {
|
329 |
+
"filePath" : "",
|
330 |
"fileNames" : {
|
331 |
"input_data" : "",
|
332 |
"output_data" : ""
|
333 |
},
|
334 |
+
"state" : "",
|
335 |
"totalBatchNum" : None,
|
336 |
"sampleRate" : None
|
337 |
}
|
|
|
813 |
# +========================================================================================+
|
814 |
# | Stage2: decode data |
|
815 |
# +========================================================================================+
|
816 |
+
# verify that all required inputs have been provided
|
817 |
@gr.on(triggers = [in_data_file.upload, in_data_file.clear, in_samplerate.change, out_json_file.change],
|
818 |
inputs = [app_info_json, in_data_file, in_samplerate], outputs = run_btn)
|
819 |
+
def check_input(app_info, in_data, samplerate):
|
820 |
if app_info["stage1"]["state"]=="finished" and in_data!=None and samplerate!="":
|
821 |
return gr.Button(interactive=True)
|
822 |
else:
|
|
|
825 |
def reset_run(app_info, in_data, samplerate, modelname):
|
826 |
stage1_info = app_info["stage1"]
|
827 |
stage2_info = app_info["stage2"]
|
828 |
+
|
829 |
+
# delete the previous folder
|
830 |
+
if stage2_info["state"] == "finished":
|
831 |
+
utils.dataDelete(stage2_info["filePath"])
|
832 |
+
# establish a new folder
|
833 |
new_filepath = app_info["rootPath"]+"stage2_"+str(random.randint(1,10000))+"/"
|
834 |
os.mkdir(new_filepath)
|
835 |
# generate the output filename
|
|
|
842 |
"input_data" : in_data,
|
843 |
"output_data" : new_filepath + new_filename
|
844 |
},
|
845 |
+
"state" : "running",
|
846 |
"sampleRate" : int(samplerate)
|
847 |
})
|
848 |
app_info["stage2"] = stage2_info
|
|
|
899 |
yield {run_btn : gr.Button(visible=True),
|
900 |
cancel_btn : gr.Button(visible=False)}
|
901 |
else:
|
902 |
+
app_info["stage2"]["state"] = "finished"
|
903 |
+
yield {app_info_json : app_info,
|
904 |
+
run_btn : gr.Button(visible=True),
|
905 |
cancel_btn : gr.Button(visible=False),
|
906 |
batch_md : gr.Markdown(visible=False),
|
907 |
out_data_file : gr.File(new_filename, visible=True)}
|
|
|
918 |
).success(
|
919 |
fn = run_model,
|
920 |
inputs = [app_info_json, in_modelname],
|
921 |
+
outputs = [app_info_json, run_btn, cancel_btn, batch_md, out_data_file]
|
922 |
)
|
923 |
|
924 |
if __name__ == "__main__":
|