| |
| import gradio as gr |
|
|
| from transformers import pipeline |
| import numpy as np |
|
|
| report_prompt_template = """ |
| this is report format |
| |
| Patient Name: [Insert name here]<br> |
| Age: [Insert age here]<br> |
| sex: [Insert here]<br> |
| Chief Complaint: [insert here]<br> |
| History of Present Illness:[insert here]<br> |
| Past Medical History: [insert here]<br> |
| Medication List: [insert here]<br> |
| Social History: [insert here]<br> |
| Family History: [insert here]<br> |
| Review of Systems: [insert here]<br> |
| ICD Code: [insert here] |
| |
| |
| convert this bellow details into above format don't add any other details .don't use the provided pdfs data's.\n\n""" |
|
|
| medical_questionnaire = [ |
| "1. please enter your personal details? name , age , gender ?", |
| "2. Describe your main symptoms? When did they start, and how have they evolved over time?", |
| "3. Have you experienced any additional symptoms aside from the primary complaint?", |
| "4. How would you rate your level of pain or discomfort on a scale of one to ten?", |
| "5. Are there any factors that exacerbate or relieve your symptoms?", |
| "6. Do you have a history of medical conditions, such as allergies, chronic illnesses, or previous surgeries? If so, please provide details.", |
| "7. What medications are you currently taking, including supplements and vitamins?", |
| "8. Have you recently traveled or been exposed to anyone with similar symptoms?", |
| "9. Do you smoke or use other forms of tobacco? Alcohol consumption?", |
| "10. Describe your diet and exercise routine.", |
| "11. Any significant changes in your life, such as stressors or recent major events?", |
| "12. Family medical history (particularly close relatives): Does anyone in your immediate family suffer from similar symptoms or health issues?", |
| "13. Social history: Marital status, occupation, living arrangements, education level, and support system.", |
| "14. Review of systems: A thorough review of body systems related to the patient’s symptoms, such as respiratory, cardiovascular, gastrointestinal, etc.", |
| "15. Have you noticed any unusual sounds or smells associated with your symptoms?", |
| "16. Have you tried any treatments or remedies thus far? If yes, what was the outcome?" |
| ] |
|
|
| global chain,id |
| chain = "" |
| id = 0 |
| sys = "You are a general family physician. Your mission is to figure out the diagnosis of the disease of the patient and figure out the next set of questions and tests to narrow down the most likely disease for the patient. Once you verify the most likely diagnosis, give the most up-to-date treatment for those diagnoses. Make sure to give the ICD code for the diagnosis if possible." |
| end_sys_prompts = "\n\ngive correct treatment and most related diagnosis with ICD code don't ask any questions. if question is not related to provided data don't give answer from this provided data's" |
|
|
| transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en") |
| with gr.Blocks() as demo: |
| chatbot = gr.Chatbot() |
| msg = gr.Textbox(label="User Input:") |
| audio_input = gr.Audio(source="microphone") |
| send = gr.Button("Send") |
| clear = gr.Button("Clear.") |
|
|
| def clear_textbox(): |
| global chain, id |
| chain = "" |
| id = 0 |
|
|
| clear.click(clear_textbox) |
|
|
| def respond(audio,message,chat_history): |
| global chain, id |
| sr, y = audio |
| y = y.astype(np.float32) |
| y /= np.max(np.abs(y)) |
| |
| message=transcriber({"sampling_rate": sr, "raw": y})["text"] |
|
|
| if id < len(medical_questionnaire): |
| if id == 0: |
| chain = chain + sys + "\n\n" + message + "\n\n" + medical_questionnaire[id] + "\n" |
| chat_history.append((message, medical_questionnaire[id])) |
| id = id + 1 |
| return "", chat_history |
| else: |
| chain = chain + message + "\n\n" + medical_questionnaire[id] + "\n" |
| chat_history.append((message, medical_questionnaire[id])) |
| id = id + 1 |
| return "", chat_history |
| else: |
| chain = chain + message + end_sys_prompts |
| diagnosis_and_treatment = "treatment" |
| diagnosis_and_treatment = str(diagnosis_and_treatment) |
|
|
| chain = chain + "\n\ntreatment & diagnosis with ICD code below\n" + diagnosis_and_treatment |
| print(chain) |
| print(id) |
|
|
| report = "report" |
| report = str(report) |
| chat_history.append((message, report.replace("\n", "<br>"))) |
|
|
| return "", chat_history |
|
|
| audio_input.stop_recording( |
| respond, [audio_input,msg,chatbot], [msg,chatbot]) |
|
|
| demo.launch() |
|
|