# language default packages from application import * # external packages import gradio as gr # internal packages from cloud_db import * from cloud_storage import * from supplier import * # get prompts, terms, outputs from the cloud def init_app_data(): ''' a function to initialize the application data from the cloud backend ''' app_data["devices"] = get_table("devices") def create_view(device): md_text = "" # add overview md_text += f"
Intended Use\n\n" md_text += device["intended_use"] + "\n
\n\n" md_text += f"
Indications\n\n" md_text += device["indications"] + "\n
\n\n" md_text += f"
Contraindications\n\n" md_text += device["contraindications"] + "\n
\n\n" return gr.update(value=md_text) def add_device( device_name, device_type, upload_instruction, intended_use, indications, contraindications ): if device_name in [d["device_name"] for d in app_data["devices"]]: return gr.update(value="Device already exists!") device = { "device_name":device_name, "device_type":device_type, } if upload_instruction: content, _ = read_pdf(upload_instruction) device["intended_use"] = get_intended_use(content) device["indications"] = get_indications(content) device["contraindications"] = get_contraindications(content) filename = upload_instruction.name.split("/")[-1] if "/" in upload_instruction.name else upload_instruction.name.split("\\")[-1] upload_fileobj(upload_instruction,"instructions",filename) else: device["intended_use"] = intended_use device["indications"] = indications device["contraindications"] = contraindications res = post_item("devices",device) app_data["current_device"] = device init_app_data() return create_view(device) def get_device( device_name ): item = get_item("devices",{"device_name":device_name})["Item"] device = db_map_to_py_dict(item) return device["device_name"], device["device_type"], device["intended_use"], device["indications"], device["contraindications"], create_view(device) def remove_device( device_name ): res = delete_item("devices",{"device_name":device_name}) return res def update_device( device_name, device_type, intended_use, indications, contraindications ): device = { "device_name":device_name, "device_type":device_type, "intended_use":intended_use, "indications":indications, "contraindications":contraindications } res = put_item("devices",device) return res def get_intended_use(content): instructions = [ "what is the intended use of this device?" ] result = send_inst(create_inst(content,instructions)) return result def get_indications(content): instructions = [ "what are the indications for use outllined for this device?" ] result = send_inst(create_inst(content,instructions)) return result def get_contraindications(content): instructions = [ "what are the contraindications for use outllined for this device?" ] result = send_inst(create_inst(content,instructions)) return result