Spaces:
Sleeping
Sleeping
File size: 2,199 Bytes
7414e20 3fdc1bc 7414e20 ef1489d 496a669 7414e20 496a669 7414e20 3fdc1bc 7414e20 3fdc1bc 7414e20 3fdc1bc 7414e20 5a09515 7414e20 5a09515 78da4aa 5a09515 7414e20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
from io import BytesIO
import gradio as gr
import pandas as pd
import requests
from matplotlib.image import imread
from ast import literal_eval
ALFRED_URL = "http://106.254.240.186:30007"
# ALFRED_URL = "http://192.168.1.11:30007"
selected_columns = ["ecg_id", "patient_id", "age", "sex", "scp_codes", "report"]
ptbxl_df = pd.read_csv("./res/ptbxl_database.csv")
ptbxl_df = ptbxl_df[selected_columns]
def get_ecg_id_from_dataframe(df: pd.DataFrame, evt: gr.SelectData):
gr.Warning(
"The analysis of the selected ECG will take about 1 to 2 minutes. Please wait patiently.",
duration=15,
)
return evt.row_value[0]
def get_ecg_image_from_dataframe(ecg_id):
response = requests.post(
f"{ALFRED_URL}/hf_demo/ptbxl_to_image", params={"ecg_id": ecg_id}, timeout=600
)
response.raise_for_status()
return imread(BytesIO(response.content))
def get_alfred_from_dataframe(ecg_id):
response = requests.post(
f"{ALFRED_URL}/hf_demo/alfred", params={"ecg_id": ecg_id}, timeout=600
)
response.raise_for_status()
return literal_eval(response.text)
with gr.Blocks() as demo:
with gr.Row():
gr_df = gr.Dataframe(
value=ptbxl_df,
interactive=False,
max_height=200,
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.",
)
with gr.Row():
ecg_id_output = gr.Textbox(label="The selected ecg_id is")
with gr.Row():
ecg_viewer = gr.Image(interactive=False, label="The selected ecg is")
with gr.Row():
alfred_result = gr.Markdown(
value="", label="Alfred said that", min_height=300, container=True
)
gr_df.select(fn=get_ecg_id_from_dataframe, inputs=gr_df, outputs=ecg_id_output)
ecg_id_output.change(
fn=get_ecg_image_from_dataframe, inputs=ecg_id_output, outputs=ecg_viewer
)
ecg_id_output.change(
fn=get_alfred_from_dataframe, inputs=ecg_id_output, outputs=alfred_result
)
demo.launch()
|