Spaces:
Sleeping
Sleeping
refactor: polish
Browse files- .gitattributes +2 -1
- app.py +63 -50
- res/screenshot_alfred-min.png +3 -0
.gitattributes
CHANGED
|
@@ -32,4 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -
|
|
|
|
|
|
| 32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -17,62 +17,75 @@ ptbxl_df = ptbxl_df[selected_columns]
|
|
| 17 |
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
-
with gr.
|
| 21 |
-
gr.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
interactive=False,
|
| 30 |
-
max_height=200,
|
| 31 |
-
label="All PTB-XL v1.3.0 data (https://physionet.org/content/ptb-xl/1.0.3/ptbxl_database.csv). You can refer to the following URL(https://physionet.org/content/ptb-xl/1.0.3/scp_statements.csv) to understand what 'scp_codes' represent.",
|
| 32 |
-
)
|
| 33 |
|
| 34 |
-
with gr.
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
value="", label="Alfred said that", min_height=300, container=True
|
| 43 |
-
)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
| 50 |
-
return {ecg_id_output: evt.row_value[0], gr_df: gr.Dataframe(visible=False)}
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
)
|
| 64 |
-
image_response.raise_for_status()
|
| 65 |
-
ecg_image = imread(BytesIO(image_response.content))
|
| 66 |
-
|
| 67 |
-
return [alfred_result, ecg_image, gr.Dataframe(visible=True)]
|
| 68 |
-
|
| 69 |
-
gr_df.select(
|
| 70 |
-
fn=get_ecg_id_from_dataframe, inputs=gr_df, outputs=[ecg_id_output, gr_df]
|
| 71 |
-
)
|
| 72 |
-
ecg_id_output.change(
|
| 73 |
-
fn=get_analysis_and_image,
|
| 74 |
-
inputs=ecg_id_output,
|
| 75 |
-
outputs=[alfred_result, ecg_viewer, gr_df],
|
| 76 |
-
)
|
| 77 |
|
| 78 |
demo.launch()
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
+
with gr.Tab("Example"):
|
| 21 |
+
with gr.Row():
|
| 22 |
+
gr.Textbox(
|
| 23 |
+
"The test app is currently not functioning properly due to DNS issues. \nBelow is the output of the actual app running internally.",
|
| 24 |
+
label="Information",
|
| 25 |
+
lines=2,
|
| 26 |
+
)
|
| 27 |
+
with gr.Row():
|
| 28 |
+
gr.Image("./res/screenshot_alfred-min.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
with gr.Tab("App"):
|
| 31 |
+
with gr.Row():
|
| 32 |
+
gr.Textbox(
|
| 33 |
+
"It takes about 10 seconds to load the PTB-XL table. Please wait for a moment. \nWhen you select the ECG to analyze from the PTB-XL table below, Alfred will begin the analysis. \nThe analysis by Alfred may take up to 5 minutes. Please wait patiently.",
|
| 34 |
+
label="Information",
|
| 35 |
+
lines=3,
|
| 36 |
+
)
|
| 37 |
+
with gr.Row():
|
| 38 |
+
gr_df = gr.Dataframe(
|
| 39 |
+
value=ptbxl_df,
|
| 40 |
+
interactive=False,
|
| 41 |
+
max_height=200,
|
| 42 |
+
label="All PTB-XL v1.3.0 data (https://physionet.org/content/ptb-xl/1.0.3/ptbxl_database.csv). You can refer to the following URL(https://physionet.org/content/ptb-xl/1.0.3/scp_statements.csv) to understand what 'scp_codes' represent.",
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
with gr.Row():
|
| 46 |
+
ecg_id_output = gr.Textbox(
|
| 47 |
+
label="The selected ecg_id is", interactive=False
|
| 48 |
+
)
|
| 49 |
|
| 50 |
+
with gr.Row():
|
| 51 |
+
ecg_viewer = gr.Image(interactive=False, label="The selected ecg is")
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
with gr.Row():
|
| 54 |
+
alfred_result = gr.Markdown(
|
| 55 |
+
value="", label="Alfred said that", min_height=300, container=True
|
| 56 |
+
)
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
def get_ecg_id_from_dataframe(df: pd.DataFrame, evt: gr.SelectData):
|
| 59 |
+
gr.Info(
|
| 60 |
+
"The analysis of the selected ECG may take up to 5 minutes. Please wait patiently.",
|
| 61 |
+
duration=15,
|
| 62 |
+
)
|
| 63 |
+
return {ecg_id_output: evt.row_value[0], gr_df: gr.Dataframe(visible=False)}
|
| 64 |
|
| 65 |
+
def get_analysis_and_image(ecg_id):
|
| 66 |
+
alfred_response = requests.post(
|
| 67 |
+
f"{ALFRED_URL}/hf_demo/alfred", params={"ecg_id": ecg_id}, timeout=600
|
| 68 |
+
)
|
| 69 |
+
alfred_response.raise_for_status()
|
| 70 |
+
alfred_result = literal_eval(alfred_response.text)
|
| 71 |
+
|
| 72 |
+
image_response = requests.post(
|
| 73 |
+
f"{ALFRED_URL}/hf_demo/ptbxl_to_image",
|
| 74 |
+
params={"ecg_id": ecg_id},
|
| 75 |
+
timeout=600,
|
| 76 |
+
)
|
| 77 |
+
image_response.raise_for_status()
|
| 78 |
+
ecg_image = imread(BytesIO(image_response.content))
|
| 79 |
+
|
| 80 |
+
return [alfred_result, ecg_image, gr.Dataframe(visible=True)]
|
| 81 |
+
|
| 82 |
+
gr_df.select(
|
| 83 |
+
fn=get_ecg_id_from_dataframe, inputs=gr_df, outputs=[ecg_id_output, gr_df]
|
| 84 |
+
)
|
| 85 |
+
ecg_id_output.change(
|
| 86 |
+
fn=get_analysis_and_image,
|
| 87 |
+
inputs=ecg_id_output,
|
| 88 |
+
outputs=[alfred_result, ecg_viewer, gr_df],
|
| 89 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
demo.launch()
|
res/screenshot_alfred-min.png
ADDED
|
Git LFS Details
|