Spaces:
Sleeping
Sleeping
refactor: set unvisible to df when alfred is running
Browse files
app.py
CHANGED
@@ -16,31 +16,6 @@ ptbxl_df = pd.read_csv("./res/ptbxl_database.csv")
|
|
16 |
ptbxl_df = ptbxl_df[selected_columns]
|
17 |
|
18 |
|
19 |
-
def get_ecg_id_from_dataframe(df: pd.DataFrame, evt: gr.SelectData):
|
20 |
-
gr.Info(
|
21 |
-
"The analysis of the selected ECG may take up to 10 minutes. Please wait patiently.",
|
22 |
-
duration=15,
|
23 |
-
)
|
24 |
-
return evt.row_value[0]
|
25 |
-
|
26 |
-
|
27 |
-
def get_ecg_image_from_dataframe(ecg_id):
|
28 |
-
response = requests.post(
|
29 |
-
f"{ALFRED_URL}/hf_demo/ptbxl_to_image", params={"ecg_id": ecg_id}, timeout=600
|
30 |
-
)
|
31 |
-
response.raise_for_status()
|
32 |
-
return imread(BytesIO(response.content))
|
33 |
-
|
34 |
-
|
35 |
-
def get_alfred_from_dataframe(ecg_id):
|
36 |
-
response = requests.post(
|
37 |
-
f"{ALFRED_URL}/hf_demo/alfred", params={"ecg_id": ecg_id}, timeout=600
|
38 |
-
)
|
39 |
-
response.raise_for_status()
|
40 |
-
|
41 |
-
return literal_eval(response.text)
|
42 |
-
|
43 |
-
|
44 |
with gr.Blocks() as demo:
|
45 |
with gr.Row():
|
46 |
gr.Textbox(
|
@@ -66,12 +41,43 @@ with gr.Blocks() as demo:
|
|
66 |
alfred_result = gr.Markdown(
|
67 |
value="", label="Alfred said that", min_height=300, container=True
|
68 |
)
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
ecg_id_output.change(
|
71 |
fn=get_ecg_image_from_dataframe, inputs=ecg_id_output, outputs=ecg_viewer
|
72 |
)
|
73 |
ecg_id_output.change(
|
74 |
-
fn=get_alfred_from_dataframe,
|
|
|
|
|
75 |
)
|
76 |
|
77 |
demo.launch()
|
|
|
16 |
ptbxl_df = ptbxl_df[selected_columns]
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
with gr.Blocks() as demo:
|
20 |
with gr.Row():
|
21 |
gr.Textbox(
|
|
|
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 10 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_ecg_image_from_dataframe(ecg_id):
|
53 |
+
response = requests.post(
|
54 |
+
f"{ALFRED_URL}/hf_demo/ptbxl_to_image",
|
55 |
+
params={"ecg_id": ecg_id},
|
56 |
+
timeout=600,
|
57 |
+
)
|
58 |
+
response.raise_for_status()
|
59 |
+
return imread(BytesIO(response.content))
|
60 |
+
|
61 |
+
def get_alfred_from_dataframe(ecg_id):
|
62 |
+
response = requests.post(
|
63 |
+
f"{ALFRED_URL}/hf_demo/alfred", params={"ecg_id": ecg_id}, timeout=600
|
64 |
+
)
|
65 |
+
response.raise_for_status()
|
66 |
+
return {
|
67 |
+
alfred_result: literal_eval(response.text),
|
68 |
+
gr_df: gr.Dataframe(visible=True),
|
69 |
+
}
|
70 |
+
|
71 |
+
gr_df.select(
|
72 |
+
fn=get_ecg_id_from_dataframe, inputs=gr_df, outputs=[ecg_id_output, gr_df]
|
73 |
+
)
|
74 |
ecg_id_output.change(
|
75 |
fn=get_ecg_image_from_dataframe, inputs=ecg_id_output, outputs=ecg_viewer
|
76 |
)
|
77 |
ecg_id_output.change(
|
78 |
+
fn=get_alfred_from_dataframe,
|
79 |
+
inputs=ecg_id_output,
|
80 |
+
outputs=[alfred_result, gr_df],
|
81 |
)
|
82 |
|
83 |
demo.launch()
|