2022-05-25 14:30:24 +08:00
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
with gr.Blocks() as demo:
|
|
|
|
error_box = gr.Textbox(label="Error", visible=False)
|
|
|
|
|
|
|
|
name_box = gr.Textbox(label="Name")
|
|
|
|
age_box = gr.Number(label="Age")
|
|
|
|
symptoms_box = gr.CheckboxGroup(["Cough", "Fever", "Runny Nose"])
|
|
|
|
submit_btn = gr.Button("Submit")
|
|
|
|
|
2022-07-25 11:46:11 +08:00
|
|
|
with gr.Column(visible=False) as output_col:
|
|
|
|
diagnosis_box = gr.Textbox(label="Diagnosis")
|
|
|
|
patient_summary_box = gr.Textbox(label="Patient Summary", visible=False)
|
2022-05-25 14:30:24 +08:00
|
|
|
|
|
|
|
def submit(name, age, symptoms):
|
|
|
|
if len(name) == 0:
|
|
|
|
return {error_box: gr.update(value="Enter name", visible=True)}
|
|
|
|
if age < 0 or age > 200:
|
|
|
|
return {error_box: gr.update(value="Enter valid age", visible=True)}
|
|
|
|
return {
|
2022-07-25 11:46:11 +08:00
|
|
|
output_col: gr.update(visible=True),
|
2022-05-25 14:30:24 +08:00
|
|
|
diagnosis_box: "covid" if "Cough" in symptoms else "flu",
|
2022-06-14 07:49:23 +08:00
|
|
|
patient_summary_box: gr.update(value=f"{name}, {age} y/o", visible=True)
|
2022-05-25 14:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
submit_btn.click(
|
|
|
|
submit,
|
|
|
|
[name_box, age_box, symptoms_box],
|
2022-07-25 11:46:11 +08:00
|
|
|
[error_box, diagnosis_box, patient_summary_box, output_col],
|
2022-05-25 14:30:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-07-25 09:18:42 +08:00
|
|
|
demo.launch()
|