File size: 3,194 Bytes
6dc443d
47d95c0
5ccc81c
 
6dc443d
 
 
72baa29
 
6dc443d
06a1d7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47d95c0
b4ee158
99e8682
 
b0c89d5
 
9cdcb63
b0c89d5
 
bdb48a4
b0c89d5
b4ee158
47d95c0
3e38893
 
99e8682
 
 
3e38893
31b3b1a
af75ec3
f2ad242
31b3b1a
af75ec3
b0c89d5
31b3b1a
06f8e37
b0c89d5
3e38893
99e8682
b4ee158
 
 
787f98f
 
 
 
 
b4ee158
06a1d7b
5ccc81c
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
72
73
74
75
76
77
78
79
from typing import Dict
from pathlib import Path
import pandas as pd
from io import StringIO

import gradio as gr

# def predict(text: str) -> Dict:
#     return {"alive": 0.9, "death": 0.1}
    
# example_list = [[1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

# # Create title, description and article strings
# title = "This is title."
# description = "This is description."
# article = "This is article."

# default_csv = "Phase,Activity,Start date,End date\n\"Mapping the Field\",\"Literature review\",2024-01-01,2024-01-31"

# def process_csv_text(temp_file):
#     if isinstance(temp_file, str):
#         print("1")
#         df = pd.read_csv(temp_file, header = "infer", sep = ",", encoding = "utf-8")
#     else:
#         print("2")
#         df = pd.read_csv(temp_file.name)
#     print("***")
#     print(df)
#     print("***")
#     return df

# with gr.Blocks() as demo:
#     upload_button = gr.UploadButton(label="Upload Timetable", file_types = ['.csv'], file_count = "single")    
#     table = gr.Dataframe(headers=["Phase", "Activity", "Start date", "End date"], type="pandas", col_count=4)
#     upload_button.upload(fn=process_csv_text, inputs=upload_button, outputs=table, api_name="upload_csv")

# demo.launch(debug=True)

def predict():
    return {"Death": 0.9, "Alive": 0.1}

def download_patient(patient_id: str) -> str:
    my_file = Path(f"Patient{patient_id}.csv")
    print(f"File to download [{str(my_file)}].")
    if not my_file.is_file():
        raise Exception(f"[{my_file}] not found.")
    print(f"Downloading file [{str(my_file)}].")
    return str(my_file)

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            patient_upload_file = gr.File(label="Upload A Patient", 
                                          file_types = ['.csv'],
                                          file_count = "single")
            with gr.Row():
                with gr.Column(min_width=100):
                    patient_1_input_btn = gr.Button("Patient 1")
                    patient_1_download_btn = gr.DownloadButton(label="Download 1", value="1")
                with gr.Column(min_width=100):
                    patient_2_input_btn = gr.Button("Patient 2")
                    patient_2_download_btn = gr.DownloadButton(label="Download 2",value="2")
                with gr.Column(min_width=100):
                    patient_3_input_btn = gr.Button("Patient 3")
                    patient_3_download_btn = gr.DownloadButton(label="Download 3", value="3")
        with gr.Column():
            result = gr.Label(num_top_classes=2, label="Predictions")
    
    # Choose a patient to predict.        
    patient_1_input_btn.click(fn=predict, inputs=None, outputs=result, api_name="predict")
    
    # Download a patient ehr profile.
    patient_1_download_btn.click(fn=download_patient, inputs=[patient_1_download_btn], outputs=[patient_1_download_btn])
    patient_2_download_btn.click(fn=download_patient, inputs=[patient_2_download_btn], outputs=[patient_2_download_btn])
    patient_3_download_btn.click(fn=download_patient, inputs=[patient_3_download_btn], outputs=[patient_3_download_btn])
    
    
demo.launch(debug=True)