tnt306's picture
Debug 18
6cbef49
raw
history blame
3.22 kB
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="Patient1.csv")
with gr.Column(min_width=100):
patient_2_input_btn = gr.Button("Patient 2")
patient_2_download_btn = gr.DownloadButton(label="Download 2", value="Patient2.csv")
with gr.Column(min_width=100):
patient_3_input_btn = gr.Button("Patient 3")
patient_3_download_btn = gr.DownloadButton(label="Download 3", value="Patient3.csv")
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)