Spaces:
Build error
Build error
| import gradio as gr | |
| import os | |
| import sys | |
| from openai import OpenAI | |
| import os | |
| api_key = os.getenv("key") | |
| client = OpenAI(api_key=api_key) | |
| first = 1 | |
| focused_section = "SECTION" | |
| first_prompt = """ | |
| You are a helpful assistant giving real-time feedback to a Community Health Worker. | |
| I want you to act as an attending physician to give immediate, specific and | |
| actionable feedback to a community health worker who is right now with | |
| a patient. They are in the process of creating an initial SOAP note of their current patient | |
| interaction, but it is important to remember the note is incomplete. I’ll first give some information about the clinic and then about | |
| the community health-worker. Remember that the SOAP note may contain both data | |
| collected today in the clinic as well as data reported from the past and both | |
| types of data might be relevant. | |
| CLINIC CONTEXT: The clinic serves patients in Kano, Nigeria. The | |
| clinic focuses on acute, immediate care and cannot expect to see the | |
| same patient for consistent follow-up care. Sometimes the clinic requires | |
| that healthcare workers create conditional treatments plans before test | |
| results are returned. The clinic has limited testing capabilities consisting | |
| of only screening tests ((Malaria RDT, Typhoid/Paratyphoid RDT, PCV, | |
| Pregnancy test, Urine Dipstick Test, H. Pylori, HIV confirmatory test | |
| (ELFA)), and a mission to avoid low value care. There are no imaging | |
| or ultrasound or other testing capabilities. There are locally prevalent | |
| illnesses such as malaria and other infectious diseases. Top causes of | |
| death in Nigeria include: Neonatal complications, Lower respiratory | |
| infections, malaria, diarrhea, TB, heart disease, stroke, maternal condi- | |
| tions, meningitis and HIV. | |
| COMMUNITY HEALTH WORKER: The community healthcare worker | |
| seeing the patient has three years of training and is experienced with | |
| maternal and child health conditions such as malaria, diarrhea, pneu- | |
| monia, etc, but they are generally limited in their diagnositc abilities | |
| DESIRED FEEDBACK: The caregiver is currently | |
| sitting with this patient. Please give concrete advice on additional actions | |
| to take and point out inconsistencies or errors in the SOAP note. The caregiver will read the response while | |
| with the patient and can act on the advice immediately, but cannot spend | |
| a lot of time reading. Your feedback should be concise and focused, | |
| and if there are no issues with the SOAP note, a very short encouraging | |
| response is sufficient. | |
| DISEASE-SPECIFIC GUIDANCE: If the patient presents with a fever and there is evidence of an alternative explanation, such as upper respiratory infection or UTI, then this fever alone does not warrant a malaria test. | |
| Malaria treatment only when malaria RDT is positive; treat with oral ACT for 3 days; if unable to take oral, use injectable ACT. | |
| Typhoid test only if patient has fever for 3 days or more with abdominal complaints such as pain, diarrhea or constipation. | |
| Typhoid treatment with oral Ciprofloxacin or Azithromycin for 5 days. | |
| H pylori test if the patient has symptoms of gastritis for more than three weeks and recurrence after treatment with antacids or PPI. | |
| H pylori positive test must be treated with triple therapy. | |
| Anemia test if patient has chronic symptoms of fatigue or shortness of breath on exertion or lack of energy or dizziness. | |
| Anemia treatment with oral iron for three months if anemia test is positive. | |
| Hypertension considered a low-priority issue by this clinic, and should only be commented on in the event of other signs of a serious cardiac condition. | |
| That concludes the context for this clinic. | |
| TASK: Give ONLY TWO SENTENCES of specific, actionable feedback to the CHEW based on what they have so far. Your feedback should only pertain to the SECTION section of the note. | |
| If a section is completely blank, don't comment on it; the CHEW likely just hasn't gotten to writing it yet. | |
| You should feel willing to make suggestions for other things to examine or additional questions, since the CHEW is with the patient right now. | |
| PATIENT RECORD: | |
| """ | |
| second_prompt = """ | |
| With your feedback so far in mind, the CHEW has changed their note to the note below. What other comments do you have for them? | |
| If they have addressed all of your previous feedback, there is no need to ask further questions. | |
| PATIENT RECORD: | |
| """ | |
| example_subjective = """SUBJECTIVE | |
| AGE | |
| 2y | |
| Gender | |
| female | |
| Chief Complaint | |
| Running Nose And Cough | |
| History of presenting Illness (HPI) | |
| Patient seen with the complain of Running nose and cough 3/7, the catarrh are associated with fever and body malaise from the patient, there is mucus when coughing more common on the night | |
| Medical History | |
| No any medical history | |
| Gynaecology Summary | |
| Nil | |
| """ | |
| example_objective = """OBJECTIVE | |
| Review of Systems | |
| Running of nose, vomiting, cough, fever and slight changes in her breathing patterns mostly on the night period | |
| Physical Examination | |
| Patient is mildly I'll looking not dehydrated and the conjunctiva is not pale, no lost of weight, no abdominal tenderness and distention no any physical discomfort | |
| Vital Signs | |
| Blood pressure(0/0 mm[Hg]) | |
| Temperature(37°C) | |
| Anthropometry | |
| Height(78 cm) Weight(11 kg) BMI(18.1 kg/m2) | |
| """ | |
| example_assessment = """ASSESSMENT | |
| Diagnosis | |
| Cough, Plasmodium falciparum malaria, unspecified | |
| Differential Diagnosis | |
| Cough, Plasmodium falciparum malaria, unspecified | |
| """ | |
| example_plan = """PLAN | |
| Treatment plan | |
| To do mRDT | |
| * Syr Loratidine 5mls bd 5/7 | |
| * Syr Paracetamol 5mls 5mls tds 3/7 | |
| * Syr Emzolyn 5ml tds 3/7 | |
| If malaria test reveals positive then add | |
| * Syr Arthemter 5mls bd 3/7 | |
| Health educate the patient on personal hygiene and environmental hygiene | |
| """ | |
| old_soap_note = "" | |
| response = "" | |
| def predict(messages): | |
| response = client.chat.completions.create( | |
| model="gpt-4o-2024-08-06", # GPT-4 Omni | |
| messages=messages, | |
| ) | |
| out = response.choices[0].message.content | |
| return out | |
| # Define your custom function to process the input text | |
| def process_text(text1, text2, text3, text4, this_section): | |
| global first, old_soap_note, response, focused_section # Declare them as global to access the variables outside the function | |
| curr_soap_note = f"SUBJECTIVE:\n{text1}\nOBJECTIVE:\n{text2}\nASSESSMENT:\n{text3}\nPLAN:\n{text4}" | |
| prompt = None | |
| first_prompt.replace(focused_section, this_section) | |
| focused_section = this_section | |
| if first == 1: | |
| prompt = [ | |
| {"role": "user", "content": first_prompt}, | |
| {"role": "user", "content": curr_soap_note} | |
| ] | |
| old_soap_note = curr_soap_note # Store the current SOAP note | |
| response = predict(prompt) | |
| return response | |
| # Create the Gradio app | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Enter Your SOAP Note Sections Below and Hit Enter to Get Your Feedback") | |
| with gr.Row(): | |
| with gr.Column(): | |
| text_box1 = gr.Textbox(label="Subjective") | |
| text_box2 = gr.Textbox(label="Objective") | |
| text_box3 = gr.Textbox(label="Assessment") | |
| text_box4 = gr.Textbox(label="Plan") | |
| with gr.Column(): | |
| output_box1 = gr.Textbox(label="Subjective Feedback", interactive=False) | |
| output_box2 = gr.Textbox(label="Objective Feedback", interactive=False) | |
| output_box3 = gr.Textbox(label="Assessment Feedback", interactive=False) | |
| output_box4 = gr.Textbox(label="Plan Feedback", interactive=False) | |
| with gr.Row(): | |
| with gr.Column(): | |
| example_note_s = gr.Textbox(label="Example Subjective", value = example_subjective) | |
| example_note_o = gr.Textbox(label="Example Objective", value = example_objective) | |
| example_note_a = gr.Textbox(label="Example Assessment", value = example_assessment) | |
| example_note_p = gr.Textbox(label="Example Plan", value = example_plan) | |
| # Submit events without "this_section" as a direct string in the inputs | |
| text_box1.submit(lambda t1, t2, t3, t4: process_text(t1, t2, t3, t4, "SUBJECTIVE"), | |
| [text_box1, text_box2, text_box3, text_box4], output_box1) | |
| text_box2.submit(lambda t1, t2, t3, t4: process_text(t1, t2, t3, t4, "OBJECTIVE"), | |
| [text_box1, text_box2, text_box3, text_box4], output_box2) | |
| text_box3.submit(lambda t1, t2, t3, t4: process_text(t1, t2, t3, t4, "ASSESSMENT"), | |
| [text_box1, text_box2, text_box3, text_box4], output_box3) | |
| text_box4.submit(lambda t1, t2, t3, t4: process_text(t1, t2, t3, t4, "PLAN"), | |
| [text_box1, text_box2, text_box3, text_box4], output_box4) | |
| # Launch the app | |
| demo.launch() | |