wogh2012 commited on
Commit
cb786a7
·
1 Parent(s): 3128959

refactor: polish

Browse files
Files changed (3) hide show
  1. .gitattributes +2 -1
  2. app.py +63 -50
  3. 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 -textres/screenshot_alfred-min.png 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 -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.Row():
21
- gr.Textbox(
22
- "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.",
23
- label="Information",
24
- lines=2,
25
- )
26
- with gr.Row():
27
- gr_df = gr.Dataframe(
28
- value=ptbxl_df,
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.Row():
35
- ecg_id_output = gr.Textbox(label="The selected ecg_id is", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- with gr.Row():
38
- ecg_viewer = gr.Image(interactive=False, label="The selected ecg is")
 
 
39
 
40
- with gr.Row():
41
- alfred_result = gr.Markdown(
42
- value="", label="Alfred said that", min_height=300, container=True
43
- )
44
 
45
- def get_ecg_id_from_dataframe(df: pd.DataFrame, evt: gr.SelectData):
46
- gr.Info(
47
- "The analysis of the selected ECG may take up to 5 minutes. Please wait patiently.",
48
- duration=15,
49
- )
50
- return {ecg_id_output: evt.row_value[0], gr_df: gr.Dataframe(visible=False)}
51
 
52
- def get_analysis_and_image(ecg_id):
53
- alfred_response = requests.post(
54
- f"{ALFRED_URL}/hf_demo/alfred", params={"ecg_id": ecg_id}, timeout=600
55
- )
56
- alfred_response.raise_for_status()
57
- alfred_result = literal_eval(alfred_response.text)
58
 
59
- image_response = requests.post(
60
- f"{ALFRED_URL}/hf_demo/ptbxl_to_image",
61
- params={"ecg_id": ecg_id},
62
- timeout=600,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

  • SHA256: 7cda136bee494a3ab212050d5920afc0e7f6f1cdcf0669b74936157b68918f23
  • Pointer size: 132 Bytes
  • Size of remote file: 1.14 MB