From 3a3a9a344283a9c93b5a0dcb073c14f4a271457c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:50:10 +0800 Subject: [PATCH 001/164] Update streamlit_app.py --- streamlit_app.py | 51 +++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 7a0ed1272052..2d7784bff87f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -13,28 +13,31 @@ In the meantime, below is an example of what you can do with just a few lines of code: """ -num_points = st.slider("Number of points in spiral", 1, 10000, 1100) -num_turns = st.slider("Number of turns in spiral", 1, 300, 31) - -indices = np.linspace(0, 1, num_points) -theta = 2 * np.pi * num_turns * indices -radius = indices - -x = radius * np.cos(theta) -y = radius * np.sin(theta) - -df = pd.DataFrame({ - "x": x, - "y": y, - "idx": indices, - "rand": np.random.randn(num_points), -}) +import streamlit as st +import pandas as pd +import numpy as np -st.altair_chart(alt.Chart(df, height=700, width=700) - .mark_point(filled=True) - .encode( - x=alt.X("x", axis=None), - y=alt.Y("y", axis=None), - color=alt.Color("idx", legend=None, scale=alt.Scale()), - size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])), - )) +st.title('Explain my test results please!') +st.header('Instructions') +st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') + + +def load_image(): + uploaded_file = st.file_uploader(label='Upload your test results image below:') + if uploaded_file is not None: + image_data = uploaded_file.getvalue() + st.image(image_data, caption='', width=600) + return image_data + +image = load_image() +if image is not None: + image = np.asarray(Image.open(BytesIO(image)).convert('RGB')) +if st.button('Process Image'): + result = ocr_model.ocr(image) + texts = [res[1][0] for res in result[0] if len(res[1][0]) > 1] + result = llm(prompt_template_extract.format(text=",".join(texts))) + print("result: ", result) + result = literal_eval(result) + result['drug'] = " ".join(result['drug'].split(" ")[:2]) + +st.caption('Disclaimer: Not medical advice, not liable, blah') From e2ff55457094120463824d977820fdfe11ab83f4 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:56:25 +0800 Subject: [PATCH 002/164] Update streamlit_app.py --- streamlit_app.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 2d7784bff87f..ec719cd2346c 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,22 +1,7 @@ -import altair as alt import numpy as np import pandas as pd import streamlit as st -""" -# Welcome to Streamlit! - -Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:. -If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community -forums](https://discuss.streamlit.io). - -In the meantime, below is an example of what you can do with just a few lines of code: -""" - -import streamlit as st -import pandas as pd -import numpy as np - st.title('Explain my test results please!') st.header('Instructions') st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') From 010ec2bf12449e651e2c52e254feb5ebdb8caa96 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:05:47 +0800 Subject: [PATCH 003/164] Update streamlit_app.py --- streamlit_app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index ec719cd2346c..a9e96df8f97a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,6 +1,6 @@ -import numpy as np -import pandas as pd import streamlit as st +import pandas as pd +import numpy as np st.title('Explain my test results please!') st.header('Instructions') @@ -10,14 +10,17 @@ def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: + st.success("Image uploaded") # Toast message image_data = uploaded_file.getvalue() - st.image(image_data, caption='', width=600) + st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens return image_data image = load_image() if image is not None: image = np.asarray(Image.open(BytesIO(image)).convert('RGB')) + if st.button('Process Image'): + st.success("HAVEN'T WROTE CODE YET TO PROCESS") # Toast message result = ocr_model.ocr(image) texts = [res[1][0] for res in result[0] if len(res[1][0]) > 1] result = llm(prompt_template_extract.format(text=",".join(texts))) From 000ad4025b8b5a7c51cd744a082e83eee3d4ae6e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:08:35 +0800 Subject: [PATCH 004/164] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 502d7d1a0d19..0fdcaf1250dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -altair +cv2 pandas streamlit +paddleocr From 515d85d900e6bec0a3d3d5a98a93fa7a4a0c3a97 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:08:49 +0800 Subject: [PATCH 005/164] Update streamlit_app.py --- streamlit_app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/streamlit_app.py b/streamlit_app.py index a9e96df8f97a..26db1a4a056f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,6 +1,10 @@ import streamlit as st import pandas as pd import numpy as np +import cv2 +import os +import base64 +from paddleocr import PPStructure,draw_structure_result,save_structure_res st.title('Explain my test results please!') st.header('Instructions') From f25775ec8911e9b0d1ddca959ab4b45b57535ee9 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:11:58 +0800 Subject: [PATCH 006/164] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0fdcaf1250dd..e4c0e638e2f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ cv2 pandas streamlit paddleocr +Pillow From 21e04bc702fb14bc35e8ccdefd2d924f0413158a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:12:25 +0800 Subject: [PATCH 007/164] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e4c0e638e2f5..6ff195c5d30c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ cv2 pandas streamlit paddleocr -Pillow +opencv-python From 09c1a8744f5476c942739512e83bdf51f195f40b Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:12:36 +0800 Subject: [PATCH 008/164] Update requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6ff195c5d30c..d7267cc3e46b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -cv2 pandas streamlit paddleocr From e98a211f340f70144a25eb51961fbc3ebb624259 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:17:09 +0800 Subject: [PATCH 009/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 26db1a4a056f..fb9b9356e794 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,7 +1,7 @@ import streamlit as st import pandas as pd import numpy as np -import cv2 +#import cv2 import os import base64 from paddleocr import PPStructure,draw_structure_result,save_structure_res From f3cc66dcff2e201ec356659c3806ce7f1f01b379 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:17:30 +0800 Subject: [PATCH 010/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index fb9b9356e794..b8ec63a7b214 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -1,10 +1,10 @@ import streamlit as st import pandas as pd import numpy as np -#import cv2 import os import base64 -from paddleocr import PPStructure,draw_structure_result,save_structure_res +#import cv2 +#from paddleocr import PPStructure,draw_structure_result,save_structure_res st.title('Explain my test results please!') st.header('Instructions') From 788906d737d684e6b8c20752d09181119026fb86 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:26:15 +0800 Subject: [PATCH 011/164] Update requirements.txt --- requirements.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d7267cc3e46b..096889738eb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,9 @@ pandas streamlit paddleocr -opencv-python +numpy==1.23.5 +opencv_contrib_python==4.9.0.80 +opencv_python==4.8.1.78 +opencv_python_headless==4.9.0.80 +paddleocr==2.6.0.1 +paddleocr.egg==info From 0b90d1179329a98eb6bec512807d75e31615ff46 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:26:33 +0800 Subject: [PATCH 012/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index b8ec63a7b214..26199ec25ef7 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,7 +3,7 @@ import numpy as np import os import base64 -#import cv2 +import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res st.title('Explain my test results please!') From 5e373c62acdceedfd2c9855927532141d0197b32 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:28:16 +0800 Subject: [PATCH 013/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 26199ec25ef7..b8ec63a7b214 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,7 +3,7 @@ import numpy as np import os import base64 -import cv2 +#import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res st.title('Explain my test results please!') From f99c28679334cffe0df935705cf394f4678b513e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:31:52 +0800 Subject: [PATCH 014/164] Update requirements.txt --- requirements.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 096889738eb5..c17c0ee45f87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,8 @@ pandas streamlit -paddleocr numpy==1.23.5 opencv_contrib_python==4.9.0.80 opencv_python==4.8.1.78 opencv_python_headless==4.9.0.80 -paddleocr==2.6.0.1 -paddleocr.egg==info +paddleocr +paddlepaddle From ffcb83709bf797cd95111ff86000b35e2c3e745e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:36:26 +0800 Subject: [PATCH 015/164] Update streamlit_app.py --- streamlit_app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/streamlit_app.py b/streamlit_app.py index b8ec63a7b214..09bf63a4a21b 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -6,6 +6,9 @@ #import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res +pip = os.popen('pip list').read() +st.code(pip,language=None) + st.title('Explain my test results please!') st.header('Instructions') st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') From 98312a8fb9d47f78fd4de50dd0b5594e340da856 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:37:33 +0800 Subject: [PATCH 016/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 09bf63a4a21b..0fb602e5fcbc 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,7 +3,7 @@ import numpy as np import os import base64 -#import cv2 +import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res pip = os.popen('pip list').read() From aeda74d68727a545975ed9bb5fade06b45c6c204 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:39:28 +0800 Subject: [PATCH 017/164] Update streamlit_app.py --- streamlit_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 0fb602e5fcbc..b855ba75d2de 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,7 +3,8 @@ import numpy as np import os import base64 -import cv2 +from paddleocr import PaddleOCR +#import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res pip = os.popen('pip list').read() From e20ed68cc0c896d76015720b78587065998b78be Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:41:15 +0800 Subject: [PATCH 018/164] Update requirements.txt --- requirements.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index c17c0ee45f87..c863b4b99230 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ pandas streamlit numpy==1.23.5 -opencv_contrib_python==4.9.0.80 -opencv_python==4.8.1.78 -opencv_python_headless==4.9.0.80 +opencv_python +opencv_python_headless paddleocr paddlepaddle From 0a4f96f7002dc4ae30b5592877770b700c3104a5 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:41:50 +0800 Subject: [PATCH 019/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index b855ba75d2de..3f079ad15432 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -4,7 +4,7 @@ import os import base64 from paddleocr import PaddleOCR -#import cv2 +import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res pip = os.popen('pip list').read() From 12055b2daaaa8ee782f423cb5ad1e987cbdd47a1 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:47:59 +0800 Subject: [PATCH 020/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 3f079ad15432..4f93cb92db68 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,8 +3,8 @@ import numpy as np import os import base64 -from paddleocr import PaddleOCR -import cv2 +#from paddleocr import PaddleOCR +#import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res pip = os.popen('pip list').read() From b5156b0905e23135f67c50c502d2a37ee9457577 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:48:17 +0800 Subject: [PATCH 021/164] Update requirements.txt --- requirements.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index c863b4b99230..980327b9f29d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,3 @@ -pandas -streamlit -numpy==1.23.5 opencv_python -opencv_python_headless paddleocr paddlepaddle From 583b7e3d753f1c83a9be0e285bb85033d87883fd Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:51:04 +0800 Subject: [PATCH 022/164] Update streamlit_app.py --- streamlit_app.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 4f93cb92db68..ee23b70cc391 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -7,9 +7,6 @@ #import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res -pip = os.popen('pip list').read() -st.code(pip,language=None) - st.title('Explain my test results please!') st.header('Instructions') st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') From f072235261a1465638c26353ef26ce6d969f4d5e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:15:03 +0800 Subject: [PATCH 023/164] Update requirements.txt --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 980327b9f29d..13602138719b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ opencv_python paddleocr paddlepaddle +streamlit +openai From 55e16f4440d5685916a8319806a84476019d2d12 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:15:58 +0800 Subject: [PATCH 024/164] Update streamlit_app.py --- streamlit_app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/streamlit_app.py b/streamlit_app.py index ee23b70cc391..3213edfbaf2c 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -11,6 +11,8 @@ st.header('Instructions') st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') +result = os.popen('pip list').read() +st.code(result, language=None) def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') From b7dcdc545100ed45e3a070a881e27da438ffb176 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:20:25 +0800 Subject: [PATCH 025/164] Update streamlit_app.py --- streamlit_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/streamlit_app.py b/streamlit_app.py index 3213edfbaf2c..be95250aafe8 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,6 +3,7 @@ import numpy as np import os import base64 +import openai #from paddleocr import PaddleOCR #import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res From 0e1ee922e49a15e2eb68ac5295434df028a51054 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:26:43 +0800 Subject: [PATCH 026/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index be95250aafe8..2f3299fb1031 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -3,7 +3,7 @@ import numpy as np import os import base64 -import openai +from openai import OpenAI #from paddleocr import PaddleOCR #import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res @@ -14,7 +14,7 @@ result = os.popen('pip list').read() st.code(result, language=None) - +client = OpenAI() def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: From 2ef4e988bdc617ed43e54df3fdfafd9dc21a592b Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:28:36 +0800 Subject: [PATCH 027/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 2f3299fb1031..dde5062a72a8 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -4,7 +4,7 @@ import os import base64 from openai import OpenAI -#from paddleocr import PaddleOCR +from paddleocr import PaddleOCR #import cv2 #from paddleocr import PPStructure,draw_structure_result,save_structure_res @@ -14,7 +14,7 @@ result = os.popen('pip list').read() st.code(result, language=None) -client = OpenAI() + def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: From 940f0064ee4c672377c3c99d119e28500fe05a94 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:36:39 +0800 Subject: [PATCH 028/164] Create packages.txt --- packages.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages.txt diff --git a/packages.txt b/packages.txt new file mode 100644 index 000000000000..f359f073a1f1 --- /dev/null +++ b/packages.txt @@ -0,0 +1 @@ +libgl1-mesa-glx From 48876ec5605e7b8cf654ce85bec053d6e00d5807 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:39:46 +0800 Subject: [PATCH 029/164] Update streamlit_app.py --- streamlit_app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index dde5062a72a8..8af85403c2b9 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -4,9 +4,9 @@ import os import base64 from openai import OpenAI -from paddleocr import PaddleOCR -#import cv2 -#from paddleocr import PPStructure,draw_structure_result,save_structure_res +#from paddleocr import PaddleOCR +import cv2 +from paddleocr import PPStructure,draw_structure_result,save_structure_res st.title('Explain my test results please!') st.header('Instructions') From 7e59c8b13aedd415e38ca5e00cbc159b26efba2a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:40:08 +0800 Subject: [PATCH 030/164] Update streamlit_app.py --- streamlit_app.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 8af85403c2b9..495c1eec9710 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,9 +12,6 @@ st.header('Instructions') st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') -result = os.popen('pip list').read() -st.code(result, language=None) - def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: From fbfe353f18d52d5fffe45168d198033b8c316631 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:40:56 +0800 Subject: [PATCH 031/164] Update streamlit_app.py --- streamlit_app.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 495c1eec9710..74ea1291bef9 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -2,11 +2,11 @@ import pandas as pd import numpy as np import os +import time import base64 from openai import OpenAI -#from paddleocr import PaddleOCR import cv2 -from paddleocr import PPStructure,draw_structure_result,save_structure_res +from paddleocr import PaddleOCR st.title('Explain my test results please!') st.header('Instructions') @@ -15,22 +15,26 @@ def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: - st.success("Image uploaded") # Toast message + st.toast("Image uploaded") # Toast message image_data = uploaded_file.getvalue() st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens return image_data + +ocr_model = PaddleOCR(use_angle_cls=True, lang='en') image = load_image() -if image is not None: - image = np.asarray(Image.open(BytesIO(image)).convert('RGB')) if st.button('Process Image'): - st.success("HAVEN'T WROTE CODE YET TO PROCESS") # Toast message + start_time = time.time() result = ocr_model.ocr(image) - texts = [res[1][0] for res in result[0] if len(res[1][0]) > 1] - result = llm(prompt_template_extract.format(text=",".join(texts))) - print("result: ", result) - result = literal_eval(result) - result['drug'] = " ".join(result['drug'].split(" ")[:2]) + inner_result = result[0] + extracted_text = '' + for idx in range(len(result)): + txt = result[idx][1][0] + extracted_text += txt + " " + end_time = time.time() + extract_time = int(end_time - start_time) + st.markdown(extracted_text) + st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success st.caption('Disclaimer: Not medical advice, not liable, blah') From bdbf4ea3749c53e167557d6b0115e1b7c4b5069e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:46:55 +0800 Subject: [PATCH 032/164] Update streamlit_app.py --- streamlit_app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 74ea1291bef9..301eecfa7d18 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -27,7 +27,6 @@ def load_image(): if st.button('Process Image'): start_time = time.time() result = ocr_model.ocr(image) - inner_result = result[0] extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From f2c6a6da728e09346d6d5e6c901cfd93267dfe47 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:59:20 +0800 Subject: [PATCH 033/164] Update streamlit_app.py --- streamlit_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/streamlit_app.py b/streamlit_app.py index 301eecfa7d18..0369b880413a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -30,6 +30,7 @@ def load_image(): extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] + st.write(txt) extracted_text += txt + " " end_time = time.time() extract_time = int(end_time - start_time) From c9d5d7df58e499b78f6aa7bc3083634154774c67 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:08:35 +0800 Subject: [PATCH 034/164] Update streamlit_app.py --- streamlit_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/streamlit_app.py b/streamlit_app.py index 0369b880413a..63abb09adba9 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -27,6 +27,7 @@ def load_image(): if st.button('Process Image'): start_time = time.time() result = ocr_model.ocr(image) + st.code(result) extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From c3b241116f0edfb9e46937baa613311939d1b639 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:13:32 +0800 Subject: [PATCH 035/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 63abb09adba9..5b029fa77c45 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -29,7 +29,7 @@ def load_image(): result = ocr_model.ocr(image) st.code(result) extracted_text = '' - for idx in range(len(result)): + for idx in range(len(result[0]): #idk why this needs a result[0] instead of result txt = result[idx][1][0] st.write(txt) extracted_text += txt + " " From d4864742198be66fc7c71b7fdd7e50a1e8a74bf6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:13:55 +0800 Subject: [PATCH 036/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 5b029fa77c45..af5b7a77be9c 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -29,7 +29,7 @@ def load_image(): result = ocr_model.ocr(image) st.code(result) extracted_text = '' - for idx in range(len(result[0]): #idk why this needs a result[0] instead of result + for idx in range(len(result[0]): txt = result[idx][1][0] st.write(txt) extracted_text += txt + " " From 9b2a6fbb9751e2d995b9a035ab698df052d90239 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:14:28 +0800 Subject: [PATCH 037/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index af5b7a77be9c..3fae157f616a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -29,7 +29,7 @@ def load_image(): result = ocr_model.ocr(image) st.code(result) extracted_text = '' - for idx in range(len(result[0]): + for idx in range(len(result[0])): #idk why this needs a result[0] instead of result txt = result[idx][1][0] st.write(txt) extracted_text += txt + " " From fe2f5f282f95325588451e611d197dde9f2678ab Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:17:17 +0800 Subject: [PATCH 038/164] Update streamlit_app.py --- streamlit_app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 3fae157f616a..610aec9c45b2 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -27,9 +27,11 @@ def load_image(): if st.button('Process Image'): start_time = time.time() result = ocr_model.ocr(image) + result = result[0] + #idk why this needs a result[0] instead of result st.code(result) extracted_text = '' - for idx in range(len(result[0])): #idk why this needs a result[0] instead of result + for idx in range(len(result)): txt = result[idx][1][0] st.write(txt) extracted_text += txt + " " From 9c4767d187962b8e5fdf01302e82ec4803ea5f20 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 13 Jan 2024 01:20:16 +0800 Subject: [PATCH 039/164] Update streamlit_app.py --- streamlit_app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 610aec9c45b2..87b1912035cf 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -33,7 +33,6 @@ def load_image(): extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] - st.write(txt) extracted_text += txt + " " end_time = time.time() extract_time = int(end_time - start_time) From 5ed1e0a365ee87343c26d1dadbd9afbd690934e0 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:14:41 +0800 Subject: [PATCH 040/164] Create main.yml --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000000..0f46cbf6bd07 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,5 @@ +name: secret-test +on: [push] +env: + API_KEY: ${{ secrets.API_KEY }} + From 8009d42a44a0f0606da9b94afbe0325a54db0a4f Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:15:56 +0800 Subject: [PATCH 041/164] Update streamlit_app.py --- streamlit_app.py | 179 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 162 insertions(+), 17 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 87b1912035cf..09534a412bb0 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -4,13 +4,104 @@ import os import time import base64 +import json from openai import OpenAI import cv2 from paddleocr import PaddleOCR -st.title('Explain my test results please!') -st.header('Instructions') -st.markdown('Take a picture of your lab test results, upload it, and we will explain it to you!') +# REMOVE THIS BEFORE COPYING TO GITHUB! +API_KEY = os.environ['API_KEY'] + +test_attributes = {} + +client = OpenAI(api_key=API_KEY) + +template_prompt = """ +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string in lower case), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". + +Example output json template +{ + "ldl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "hdl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "total_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "mcv":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "hb:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "uric_acid:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "hba1c:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "systolic_bp:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "diastolic_bp:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "height:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "weight:{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + } +} + +Health screening result: +""" def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') @@ -19,24 +110,78 @@ def load_image(): image_data = uploaded_file.getvalue() st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens return image_data + +st.title('Explain my test results please!') +st.header('Instructions') +st.markdown('Answer the questions, take a picture of your lab test results, upload it, and we will explain it to you!') + +# User inputs +age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") +sex = st.selectbox("Select your sex", ["Female","Male"]) +race = st.selectbox("Select your race", ["Chinese", "Malay", "Indian", "Others"]) +smoker = st.checkbox("Are you a smoker?") +stroke = st.checkbox("Have you ever had a stroke?") +diabetes = st.checkbox("Do you have a history of diabetes?") +heart_attack = st.checkbox("Have you ever had a heart attack?") +on_bp_meds = st.checkbox("Are you taking blood pressure medication?") +systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') image = load_image() -if st.button('Process Image'): - start_time = time.time() - result = ocr_model.ocr(image) - result = result[0] - #idk why this needs a result[0] instead of result - st.code(result) - extracted_text = '' - for idx in range(len(result)): - txt = result[idx][1][0] - extracted_text += txt + " " - end_time = time.time() - extract_time = int(end_time - start_time) - st.markdown(extracted_text) - st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success +if st.button('Analyse my results'): + # Save test attributes + test_attributes["age"] = age + test_attributes["sex"] = sex + test_attributes["race"] = race + test_attributes["smoker"] = smoker #true or false + test_attributes["stroke"] = stroke + test_attributes["diabetes"] = diabetes + test_attributes["heart_attack"] = heart_attack + test_attributes["on_BP_meds"] = on_bp_meds + test_attributes["systolic_blood_pressure"] = systolic_bp #null or integer + st.json(test_attributes) + # Extract text from image + if not image: #Image not uploaded + st.error("Upload an image of your test results first!",icon="🚨") + else: # Image uploaded + ocr_start_time = time.time() + result = ocr_model.ocr(image) + extracted_text = '' + for idx in range(len(result)): + txt = result[idx][1][0] + extracted_text += txt + " " + ocr_end_time = time.time() + ocr_time = int(ocr_end_time - ocr_start_time) + st.markdown(extracted_text) + st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success + # Remove NRIC from extracted text + # Extract structured data from text using ChatGPT + # TODO: PUT TRY AND ERROR IF FAIL + extract_start_time = time.time() + extract_prompt = f"{template_prompt} {extracted_text}" + response = client.chat.completions.create( + model="gpt-3.5-turbo-1106", + response_format={ "type": "json_object" }, + messages=[ + {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, + {"role": "user", "content": extract_prompt} + ] + ) + test_results = json.loads(response.choices[0].message.content) + st.json(test_results) + st.text(response.usage) + extract_end_time = time.time() + extract_time = int(extract_end_time - extract_start_time) + st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success + for test_name, test_info in test_results.items(): + if test_info["test_found"]: + st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") + st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") + #st.markdown(f"**Reference Range:** {test_info['test_ref_min']} - {test_info['test_ref_max']} {test_info['test_unit']}") + st.text("") + # Insert YT logic + st.caption('Disclaimer: Not medical advice, not liable, blah') From 871875a56326ccc89c2eed88c2cf9bcd734b3718 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:20:27 +0800 Subject: [PATCH 042/164] Update main.yml --- .github/workflows/main.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f46cbf6bd07..47512c87d806 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,9 @@ name: secret-test on: [push] -env: - API_KEY: ${{ secrets.API_KEY }} - +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - name: Hello world action + env: # Or as an environment variable + API_KEY: ${{ secrets.API_KEY }} From 190a14d4b08cabf1169694a842f4859f1f8c53e0 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:23:46 +0800 Subject: [PATCH 043/164] Update streamlit_app.py --- streamlit_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/streamlit_app.py b/streamlit_app.py index 09534a412bb0..01e1266f8984 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -148,6 +148,7 @@ def load_image(): else: # Image uploaded ocr_start_time = time.time() result = ocr_model.ocr(image) + result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From cab572f9cf940eb1894657577eeeaabad32b691a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:01:18 +0800 Subject: [PATCH 044/164] Update main.yml --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 47512c87d806..777784f9e40e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,5 +5,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Hello world action - env: # Or as an environment variable + run: python streamlit-example.py + env: API_KEY: ${{ secrets.API_KEY }} From a402e69e5c9df4687a44b7e9c18c91e693892c96 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:05:41 +0800 Subject: [PATCH 045/164] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 777784f9e40e..d9e556444ccd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Hello world action - run: python streamlit-example.py + run: python streamlit-app.py env: API_KEY: ${{ secrets.API_KEY }} From c06f316ca121b1e17aebbf46808fc6432f0e0d03 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:13:07 +0800 Subject: [PATCH 046/164] Update main.yml --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9e556444ccd..33054801100d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,8 @@ jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v2 - name: Hello world action run: python streamlit-app.py env: From f5e0a1eef69becef81aaa39a8b3728d70d80ffd6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:19:15 +0800 Subject: [PATCH 047/164] Update main.yml --- .github/workflows/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 33054801100d..e8e7778314fc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,9 +4,7 @@ jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - name: Hello world action - run: python streamlit-app.py + run: python streamlit-example/streamlit_app.py env: API_KEY: ${{ secrets.API_KEY }} From 9c5bc509c82dfeed9be2babc742a365e3b9c5c5c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:21:16 +0800 Subject: [PATCH 048/164] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8e7778314fc..4700438890f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Hello world action - run: python streamlit-example/streamlit_app.py + run: echo "JUST LOADING SECRET ONLY" env: API_KEY: ${{ secrets.API_KEY }} From 2a129c5d8dabfdcfc036b4d84bb90689d7d1c11e Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sat, 20 Jan 2024 22:13:22 +0800 Subject: [PATCH 049/164] add quotation marks --- streamlit_app.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 01e1266f8984..33749a16f116 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -49,49 +49,49 @@ "test_ref_min":False, "test_ref_max":False }, - "hb:{ + "hb":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "uric_acid:{ + "uric_acid":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "hba1c:{ + "hba1c":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "systolic_bp:{ + "systolic_bp":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "diastolic_bp:{ + "diastolic_bp":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "height:{ + "height":{ "test_found":False, "test_value":False, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, - "weight:{ + "weight":{ "test_found":False, "test_value":False, "test_unit":False, From 3831df2d909ad6b81e8e41ac4449616e4959db45 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sat, 20 Jan 2024 22:43:13 +0800 Subject: [PATCH 050/164] added RBC count --- streamlit_app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/streamlit_app.py b/streamlit_app.py index 33749a16f116..bdc3d43abda2 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -56,6 +56,13 @@ "test_ref_min":False, "test_ref_max":False }, + "rbc_count":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, "uric_acid":{ "test_found":False, "test_value":False, From 3693ee99d4f83543d6ca421677bcd89782d7c34a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 00:13:26 +0800 Subject: [PATCH 051/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index bdc3d43abda2..6990203f5c5d 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -56,7 +56,7 @@ "test_ref_min":False, "test_ref_max":False }, - "rbc_count":{ + "rbc_count":{ "test_found":False, "test_value":False, "test_unit":False, From c8fe213b40994167603b74eec64ef48a0a804f0c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 00:17:50 +0800 Subject: [PATCH 052/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 6990203f5c5d..2446bb59fc6d 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -17,7 +17,7 @@ client = OpenAI(api_key=API_KEY) template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string in lower case), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Example output json template { From 3a4a476085f591351e7caf8d2b1bfa98c01b5288 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 14:16:14 +0800 Subject: [PATCH 053/164] add files --- anaemia.py | 29 ++++++ lipids_ranges.py | 227 +++++++++++++++++++++++++++++++++++++++++++++++ refranges.py | 103 +++++++++++++++++++++ 3 files changed, 359 insertions(+) create mode 100644 anaemia.py create mode 100644 lipids_ranges.py create mode 100644 refranges.py diff --git a/anaemia.py b/anaemia.py new file mode 100644 index 000000000000..1414700a86ba --- /dev/null +++ b/anaemia.py @@ -0,0 +1,29 @@ +testdict = { + "mcv":{ + "test_found":True, + "test_value":60, + "test_unit":False, + "test_ref_min":85, + "test_ref_max":False + }, + "rbc_count":{ + "test_found":True, + "test_value":60, + "test_unit":False, + "test_ref_min":85, + "test_ref_max":False + } + "hb":{ + "test_found":True, + "test_value":11, + "test_unit":False, + "test_ref_min":12, + "test_ref_max":16 + }, +} +#mcv need fl RBC need 10^6/uL +def anaemia_analysis (hbdict): + hblevel = hbdict["hb"]["test_value"] + anaemia = bool(hblevel < hbdict["hb"]["test_ref_min"]) + + return result \ No newline at end of file diff --git a/lipids_ranges.py b/lipids_ranges.py new file mode 100644 index 000000000000..f03ca7a47363 --- /dev/null +++ b/lipids_ranges.py @@ -0,0 +1,227 @@ +import json + + +# Open the file containing the JSON data +with open('Sample json extraction\sample json extraction.txt') as f: + # Load the JSON data from the file + data = json.load(f) + +# add data to a dictionary where key is test name and value is dictionary of test name/results etc. +masterdict = {} +# Access each individual object and list the attributes +for dict in data['test_results']: + masterdict [dict["test_name"]] = dict + +testdict = { + "CHOLESTEROL": + { + "test_name": "CHOLESTEROL", + "test_value": 5.1, + "test_ref_min": "NA", + "test_ref_max": "NA", + "test_unit": "mmol/l" + }, + "HDL CHOLESTEROL": + { + "test_name": "HDL CHOLESTEROL", + "test_value": 1.6, + "test_ref_min": "NA", + "test_ref_max": "NA", + "test_unit": "mmol/l" + } +} + + +#access value by e.g. masterdict["CHOLESTEROL"]["test_value"] +#print (f"master dict {masterdict}") + +#sample of attributes needed +test_attributes = { + "age" : 35, + "sex" :"male", #0 for male, 1 for female + "smoker" : True, + "stroke" : False, + "diabetes" : False , + "heart_attack" : False , + "race" :"chinese", + "systolic_blood_pressure" : 140, + "on_BP_meds" : False, + "total_cholesterol" : testdict["CHOLESTEROL"], #masterdict["CHOLESTEROL"] + "hdl_cholesterol" : testdict["HDL CHOLESTEROL"] #masterdict["HDL CHOLESTEROL"] +} + +def getLDLtarget (attributes): + if(attributes["stroke"]): + return 1.8 + if(attributes["diabetes"]): + return 2.6 + if(attributes["heart_attack"]): + return 1.4 + #SGFRS scoring, only if no stroke or diabetes then proceed + LDLtarget = 0 + #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 + # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score + # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; + # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 + agedict = { + 20 : { + "age": ( + (-9, -7), #20-34 (M, F) + (-4, -3)), #35-39 (M, F)) + "tchol": ( + (4, 4), #4.1-5.1 (M, F) + (7, 8), #5.2-6.1 (M, F) + (9, 11), #6.2-7.2 (M, F) + (11, 13)),#>=7.3 (M, F) + "smoker": (8, 9) + }, + 40 :{ + "age": (( + 0, 0), + (3, 3)), + "tchol" : ( + (3, 3), + (5, 6), + (6, 8), + (8, 10)), + "smoker": (5, 7) + }, + 50 :{ + "age": ( + (6, 6), + (8, 8)), + "tchol" : ( + (2, 2), + (3, 4), + (4, 5), + (5, 7)), + "smoker": (3, 4) + }, + 60 :{ + "age": ( + (10, 10), + (11, 12)), + "tchol" : ( + (1, 1), + (1, 2), + (2, 3), + (3, 4)), + "smoker": (1, 2) + }, + 70 :{ + "age": ( + (12, 14), + (13, 16)), + "tchol" : ( + (0, 1), + (0, 1), + (1, 2), + (1, 2)), + "smoker": (1, 1) + } + } + #dictionary corresponding to ageless variables + otherriskdict = { + "hdl" : (-1, 0, 1, 2), #regardless of gender, for ranges >=1.6, 1.3-1.5, 1.0-1.2, <1.0 + "sysBP" : ( + ((0, 1),(1, 3)), #untreated M, F , treated M, F for 120-129 + ((1, 2),(2, 4)), #130-139 + ((1, 3),(2, 5)), #140-159 + ((2, 4),(3, 6)), #>160 + ) + } + #start scoring + print (f"scoring now") + score = 0 + sex = 0 if attributes["sex"] == "male" else 1 + age = attributes["age"] + tcval = attributes ["total_cholesterol"]["test_value"] + if attributes ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + if tcval > 280: cholbracket = 3 + elif tcval > 240: cholbracket = 2 + elif tcval > 200: cholbracket = 1 + elif tcval > 160: cholbracket = 0 + else: cholbracket = -1 + elif attributes ["total_cholesterol"]["test_unit"].lower() =="mmol/l": + if tcval > 7.2: cholbracket = 3 + elif tcval > 6.1: cholbracket = 2 + elif tcval > 5.1: cholbracket = 1 + elif tcval > 4.1: cholbracket = 0 + else: cholbracket = -1 + else: + cholbracket = -1 + print ("invalid cholesterol units") + + hval = attributes ["hdl_cholesterol"]["test_value"] + if attributes ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + if hval > 59: hdlbracket = 0 + elif hval > 49: hdlbracket = 1 + elif hval > 40: hdlbracket = 2 + else: hdlbracket = 3 + if attributes ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": + if hval > 1.5: hdlbracket = 0 + elif hval > 1.2: hdlbracket = 1 + elif hval > 1: hdlbracket = 2 + else: hdlbracket = 3 + else: + hdlbracket = -1 + print ("invalid cholesterol units") + + bval = attributes ["systolic_blood_pressure"] + if bval > 159: bpbracket = 3 + elif bval > 139: bpbracket = 2 + elif bval > 129: bpbracket = 1 + elif bval > 119: bpbracket = 0 + else: bpbracket = -1 + + # HDL points + if hdlbracket >-1: + score += otherriskdict["hdl"][hdlbracket] + + #systolic BP points + treated = 1 if attributes["on_BP_meds"] else 0 + if bpbracket > -1: + score += otherriskdict["sysBP"][bpbracket][treated][sex] + print (f"score after BP/hdl {score}") + agescore = 0 + if age >70: + curdict = agedict[70] + agebracket = 0 if age <75 else 1 + elif age >60: + curdict = agedict[60] + agebracket = 0 if age <65 else 1 + elif age >50: + curdict = agedict[50] + agebracket = 0 if age <55 else 1 + elif age >40: + curdict = agedict[40] + agebracket = 0 if age <45 else 1 + elif age >20: + curdict = agedict[20] + agebracket = 0 if age <35 else 1 + else: + print ("you are too young to use this calculator") + return 0 + + # age only points + agescore += curdict["age"][agebracket][sex] + print (f"agescore {agescore} after age only") + + # age and cholesterol points + if cholbracket > -1: #no points if cholesterol is <4.1 + agescore += curdict["tchol"][cholbracket][sex] + print (f"agescore {agescore} after chol") + + # age and smoking points + if attributes["smoker"]: + agescore += curdict["smoker"][sex] + print (f"agescore {agescore} after smoking") + + score += agescore + + + print (f"score {score}") + return LDLtarget + +LDLtarget = getLDLtarget (test_attributes) +print (f"LDL target {LDLtarget}") diff --git a/refranges.py b/refranges.py new file mode 100644 index 000000000000..c77bf7defedc --- /dev/null +++ b/refranges.py @@ -0,0 +1,103 @@ +import json +from lipids_ranges import getLDLtarget + +testdict = { + "ldl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "hdl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "total_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "mcv":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "rbc_count":{ + "test_found":True, + "test_value":60, + "test_unit":False, + "test_ref_min":85, + "test_ref_max":False + } + "hb":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "uric_acid":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "hba1c":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "systolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "diastolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "height":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "weight":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + } +} + +test_attributes = { + "age" : 35, + "sex" :"male", #0 for male, 1 for female + "smoker" : True, + "stroke" : False, + "diabetes" : False , + "heart_attack" : False , + "race" :"chinese", + "systolic_blood_pressure" : 140, + "on_BP_meds" : False, + "total_cholesterol" : testdict["CHOLESTEROL"], #masterdict["CHOLESTEROL"] + "hdl_cholesterol" : testdict["HDL CHOLESTEROL"] #masterdict["HDL CHOLESTEROL"] +} \ No newline at end of file From 7b394b7e07d0cdf9f565b0e8a06f11fc33fd2f0c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:53:41 +0800 Subject: [PATCH 054/164] Add files via upload --- chatgpt_values.py | 124 ++++++++++++++++++++++++++++++++++++++++++++++ image_loading.py | 30 +++++++++++ 2 files changed, 154 insertions(+) create mode 100644 chatgpt_values.py create mode 100644 image_loading.py diff --git a/chatgpt_values.py b/chatgpt_values.py new file mode 100644 index 000000000000..e2b1d8f85d60 --- /dev/null +++ b/chatgpt_values.py @@ -0,0 +1,124 @@ +import streamlit as st +import pandas as pd +import numpy as np +import os +import time +import base64 +import json +import cv2 +from openai import OpenAI +from paddleocr import PaddleOCR + +# REMOVE THIS BEFORE COPYING TO GITHUB! +#API_KEY = os.environ['API_KEY'] +API_KEY = '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' + +client = OpenAI(api_key=API_KEY) + + +template_prompt = """ +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". + +Example output json template +{ + "ldl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "hdl_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "total_cholesterol": { + "test_found":True, + "test_value":20, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "mcv":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "hb":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "rbc_count":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "uric_acid":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "hba1c":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "systolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "diastolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "height":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "weight":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + } +} + +Health screening result: +""" + +def extract_values(extracted_text): + extract_prompt = f"{template_prompt} {extracted_text}" + response = client.chat.completions.create( + model="gpt-3.5-turbo-1106", + response_format={ "type": "json_object" }, + messages=[ + {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, + {"role": "user", "content": extract_prompt} + ] + ) + test_results = json.loads(response.choices[0].message.content) + return response,test_results \ No newline at end of file diff --git a/image_loading.py b/image_loading.py new file mode 100644 index 000000000000..26c991418a5d --- /dev/null +++ b/image_loading.py @@ -0,0 +1,30 @@ +import streamlit as st +import pandas as pd +import numpy as np +import os +import time +import base64 +import json +import cv2 +from openai import OpenAI +from paddleocr import PaddleOCR + +ocr_model = PaddleOCR(use_angle_cls=True, lang='en') + +def load_image(): + uploaded_file = st.file_uploader(label='Upload your test results image below:') + if uploaded_file is not None: + st.toast("Image uploaded") # Toast message + image_data = uploaded_file.getvalue() + st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens + return image_data + + +def extract_text(image): + result = ocr_model.ocr(image) + #result = result[0] #idk why this needs a result[0] instead of result for Github + extracted_text = '' + for idx in range(len(result)): + txt = result[idx][1][0] + extracted_text += txt + " " + return extracted_text \ No newline at end of file From 608606ee268852a8015c8d041c0b84d5bf481392 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:58:17 +0800 Subject: [PATCH 055/164] Update chatgpt_values.py --- chatgpt_values.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index e2b1d8f85d60..42860f58096a 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -10,8 +10,7 @@ from paddleocr import PaddleOCR # REMOVE THIS BEFORE COPYING TO GITHUB! -#API_KEY = os.environ['API_KEY'] -API_KEY = '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' +API_KEY = os.environ['API_KEY'] client = OpenAI(api_key=API_KEY) @@ -121,4 +120,4 @@ def extract_values(extracted_text): ] ) test_results = json.loads(response.choices[0].message.content) - return response,test_results \ No newline at end of file + return response,test_results From f70324f1186c4427927baf0ca2eec4ee83ad054f Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:59:39 +0800 Subject: [PATCH 056/164] Update streamlit_app.py --- streamlit_app.py | 131 ++--------------------------------------------- 1 file changed, 5 insertions(+), 126 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 2446bb59fc6d..c56112cdc3aa 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -5,119 +5,14 @@ import time import base64 import json -from openai import OpenAI import cv2 +from openai import OpenAI from paddleocr import PaddleOCR - -# REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['API_KEY'] +from image_loading import load_image, extract_text +from chatgpt_values import extract_values test_attributes = {} -client = OpenAI(api_key=API_KEY) - -template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". - -Example output json template -{ - "ldl_cholesterol": { - "test_found":True, - "test_value":20, - "test_unit":"mmol/l", - "test_ref_min":False, - "test_ref_max":False - }, - "hdl_cholesterol": { - "test_found":True, - "test_value":20, - "test_unit":"mmol/l", - "test_ref_min":False, - "test_ref_max":False - }, - "total_cholesterol": { - "test_found":True, - "test_value":20, - "test_unit":"mmol/l", - "test_ref_min":False, - "test_ref_max":False - }, - "mcv":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "hb":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "rbc_count":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "uric_acid":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "hba1c":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "systolic_bp":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "diastolic_bp":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "height":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "weight":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - } -} - -Health screening result: -""" - -def load_image(): - uploaded_file = st.file_uploader(label='Upload your test results image below:') - if uploaded_file is not None: - st.toast("Image uploaded") # Toast message - image_data = uploaded_file.getvalue() - st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens - return image_data - st.title('Explain my test results please!') st.header('Instructions') st.markdown('Answer the questions, take a picture of your lab test results, upload it, and we will explain it to you!') @@ -132,8 +27,6 @@ def load_image(): heart_attack = st.checkbox("Have you ever had a heart attack?") on_bp_meds = st.checkbox("Are you taking blood pressure medication?") systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) - -ocr_model = PaddleOCR(use_angle_cls=True, lang='en') image = load_image() @@ -154,12 +47,7 @@ def load_image(): st.error("Upload an image of your test results first!",icon="🚨") else: # Image uploaded ocr_start_time = time.time() - result = ocr_model.ocr(image) - result = result[0] #idk why this needs a result[0] instead of result for Github - extracted_text = '' - for idx in range(len(result)): - txt = result[idx][1][0] - extracted_text += txt + " " + extracted_text = extract_text(image) ocr_end_time = time.time() ocr_time = int(ocr_end_time - ocr_start_time) st.markdown(extracted_text) @@ -169,16 +57,7 @@ def load_image(): # Extract structured data from text using ChatGPT # TODO: PUT TRY AND ERROR IF FAIL extract_start_time = time.time() - extract_prompt = f"{template_prompt} {extracted_text}" - response = client.chat.completions.create( - model="gpt-3.5-turbo-1106", - response_format={ "type": "json_object" }, - messages=[ - {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, - {"role": "user", "content": extract_prompt} - ] - ) - test_results = json.loads(response.choices[0].message.content) + response,test_results = extract_values(extracted_text) # use chatgpt to extract st.json(test_results) st.text(response.usage) extract_end_time = time.time() From 08b84f1d5c219b77f99c1c1e4273348e0c57b4cc Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:00:14 +0800 Subject: [PATCH 057/164] Update image_loading.py --- image_loading.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image_loading.py b/image_loading.py index 26c991418a5d..10baad07abe5 100644 --- a/image_loading.py +++ b/image_loading.py @@ -22,9 +22,9 @@ def load_image(): def extract_text(image): result = ocr_model.ocr(image) - #result = result[0] #idk why this needs a result[0] instead of result for Github + result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] extracted_text += txt + " " - return extracted_text \ No newline at end of file + return extracted_text From 11f70f3532fbd9bb1a487cb473bb90db09fb5591 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:05:59 +0800 Subject: [PATCH 058/164] Update image_loading.py --- image_loading.py | 1 - 1 file changed, 1 deletion(-) diff --git a/image_loading.py b/image_loading.py index 10baad07abe5..96a9272cdb63 100644 --- a/image_loading.py +++ b/image_loading.py @@ -14,7 +14,6 @@ def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: - st.toast("Image uploaded") # Toast message image_data = uploaded_file.getvalue() st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens return image_data From ca2f1b44f36608e51affaccf5a487f9c2334b3b8 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:09:00 +0800 Subject: [PATCH 059/164] Update chatgpt_values.py --- chatgpt_values.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 42860f58096a..7abe2545fa00 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -14,7 +14,6 @@ client = OpenAI(api_key=API_KEY) - template_prompt = """ Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". From c5f03cc8cd6889c911a36b26ee6d5cdf3e87474d Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:13:22 +0800 Subject: [PATCH 060/164] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4700438890f7..1e57e3bf4010 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,3 +8,4 @@ jobs: run: echo "JUST LOADING SECRET ONLY" env: API_KEY: ${{ secrets.API_KEY }} + # update From 35db690624aa3c2a629e7203f4b584a0ceea926f Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:22:21 +0800 Subject: [PATCH 061/164] Update streamlit_app.py --- streamlit_app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/streamlit_app.py b/streamlit_app.py index c56112cdc3aa..a1a8c6f76d86 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -11,6 +11,8 @@ from image_loading import load_image, extract_text from chatgpt_values import extract_values +ocr_model = PaddleOCR(use_angle_cls=True, lang='en') + test_attributes = {} st.title('Explain my test results please!') From cfa600a3e19a370d9c44a0af8888805ac48a93a6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:22:35 +0800 Subject: [PATCH 062/164] Update image_loading.py --- image_loading.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/image_loading.py b/image_loading.py index 96a9272cdb63..135ac4b60d7b 100644 --- a/image_loading.py +++ b/image_loading.py @@ -9,8 +9,6 @@ from openai import OpenAI from paddleocr import PaddleOCR -ocr_model = PaddleOCR(use_angle_cls=True, lang='en') - def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: From dd9b20fb023e962792fd0e3d7ab1493ec0a92fcb Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:23:18 +0800 Subject: [PATCH 063/164] Update image_loading.py --- image_loading.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/image_loading.py b/image_loading.py index 135ac4b60d7b..96a9272cdb63 100644 --- a/image_loading.py +++ b/image_loading.py @@ -9,6 +9,8 @@ from openai import OpenAI from paddleocr import PaddleOCR +ocr_model = PaddleOCR(use_angle_cls=True, lang='en') + def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: From 1d9af1b087208a72b293e5673623fb9db447747b Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:24:37 +0800 Subject: [PATCH 064/164] Update image_loading.py --- image_loading.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/image_loading.py b/image_loading.py index 96a9272cdb63..cce738b1ccf9 100644 --- a/image_loading.py +++ b/image_loading.py @@ -9,9 +9,8 @@ from openai import OpenAI from paddleocr import PaddleOCR -ocr_model = PaddleOCR(use_angle_cls=True, lang='en') -def load_image(): +def load_image(ocr_model): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: image_data = uploaded_file.getvalue() From b6cc94e048ceaf7d889618631e5f2d319b38727c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:25:40 +0800 Subject: [PATCH 065/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index a1a8c6f76d86..785e491b8ffe 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -30,7 +30,7 @@ on_bp_meds = st.checkbox("Are you taking blood pressure medication?") systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) -image = load_image() +image = load_image(ocr_model) if st.button('Analyse my results'): # Save test attributes From a9f7683a08d9b758044e5cf249ead26d4bb51692 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:27:14 +0800 Subject: [PATCH 066/164] Update image_loading.py --- image_loading.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image_loading.py b/image_loading.py index cce738b1ccf9..5e92396877eb 100644 --- a/image_loading.py +++ b/image_loading.py @@ -10,7 +10,7 @@ from paddleocr import PaddleOCR -def load_image(ocr_model): +def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: image_data = uploaded_file.getvalue() @@ -18,7 +18,7 @@ def load_image(ocr_model): return image_data -def extract_text(image): +def extract_text(image,ocr_model): result = ocr_model.ocr(image) result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' From 594a8125c2a3356779603596b963a91ab4f811a2 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:27:47 +0800 Subject: [PATCH 067/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 785e491b8ffe..be77892f8acb 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -30,7 +30,7 @@ on_bp_meds = st.checkbox("Are you taking blood pressure medication?") systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) -image = load_image(ocr_model) +image = load_image() if st.button('Analyse my results'): # Save test attributes @@ -49,7 +49,7 @@ st.error("Upload an image of your test results first!",icon="🚨") else: # Image uploaded ocr_start_time = time.time() - extracted_text = extract_text(image) + extracted_text = extract_text(image,ocr_model) ocr_end_time = time.time() ocr_time = int(ocr_end_time - ocr_start_time) st.markdown(extracted_text) From 470fc6ffaf802fcec058ebc9d544c373c8871b41 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:32:48 +0800 Subject: [PATCH 068/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 7abe2545fa00..382953ba6af0 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -10,7 +10,7 @@ from paddleocr import PaddleOCR # REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['API_KEY'] +API_KEY = os.environ['OPENAI_KEY'] client = OpenAI(api_key=API_KEY) From c0ff4c0d17181847c113592f905ecf021a9f9adf Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:33:15 +0800 Subject: [PATCH 069/164] Update main.yml --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1e57e3bf4010..afa20161970e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,5 +7,4 @@ jobs: - name: Hello world action run: echo "JUST LOADING SECRET ONLY" env: - API_KEY: ${{ secrets.API_KEY }} - # update + OPENAI_KEY: ${{ secrets.OPENAI_KEY }} From 7221c2dc8c9a7f53c28b7fa0c12ae72174ec367d Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:35:23 +0800 Subject: [PATCH 070/164] Update chatgpt_values.py --- chatgpt_values.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 382953ba6af0..5a25b39efb81 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -9,11 +9,6 @@ from openai import OpenAI from paddleocr import PaddleOCR -# REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['OPENAI_KEY'] - -client = OpenAI(api_key=API_KEY) - template_prompt = """ Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". From 6de526b605d6ad54e49066d82297f6ab8bb51ce8 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:36:03 +0800 Subject: [PATCH 071/164] Update streamlit_app.py --- streamlit_app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index be77892f8acb..dd2aae609eb2 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -11,6 +11,10 @@ from image_loading import load_image, extract_text from chatgpt_values import extract_values +# REMOVE THIS BEFORE COPYING TO GITHUB! +API_KEY = os.environ['OPENAI_KEY'] +client = OpenAI(api_key=API_KEY) + ocr_model = PaddleOCR(use_angle_cls=True, lang='en') test_attributes = {} @@ -59,7 +63,7 @@ # Extract structured data from text using ChatGPT # TODO: PUT TRY AND ERROR IF FAIL extract_start_time = time.time() - response,test_results = extract_values(extracted_text) # use chatgpt to extract + response,test_results = extract_values(client,extracted_text) # use chatgpt to extract st.json(test_results) st.text(response.usage) extract_end_time = time.time() From fb1849865a94c52f5921c3f9dc37db5771241f37 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:38:19 +0800 Subject: [PATCH 072/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index dd2aae609eb2..11492f0f5574 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -13,7 +13,7 @@ # REMOVE THIS BEFORE COPYING TO GITHUB! API_KEY = os.environ['OPENAI_KEY'] -client = OpenAI(api_key=API_KEY) +client = OpenAI(api_key=API_KEY) #etest ocr_model = PaddleOCR(use_angle_cls=True, lang='en') From 656ba7f37bca1bbde89eeef1290740ad9d385c39 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:19:26 +0800 Subject: [PATCH 073/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 5a25b39efb81..8a2838907cd1 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -56,7 +56,7 @@ "test_ref_min":False, "test_ref_max":False }, - "uric_acid":{ + "glucose":{ "test_found":False, "test_value":False, "test_unit":False, From 24de6de2070e7ee519ac3672b7f420b08716f1a6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:21:43 +0800 Subject: [PATCH 074/164] Update main.yml --- .github/workflows/main.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index afa20161970e..4fe8420e42f0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,15 @@ -name: secret-test +name: Use OpenAI Secret + on: [push] + jobs: - Explore-GitHub-Actions: + access-secret: runs-on: ubuntu-latest steps: - - name: Hello world action - run: echo "JUST LOADING SECRET ONLY" - env: + - name: Check out repository code + uses: actions/checkout@v2 + + - name: Access OpenAI Key + run: echo "The secret is ${{ secrets.OPENAI_KEY }}" + env: OPENAI_KEY: ${{ secrets.OPENAI_KEY }} From d199f88c443eaf01d80ba784f5ef658262a7655e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:23:26 +0800 Subject: [PATCH 075/164] Update streamlit_app.py --- streamlit_app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 11492f0f5574..08a47b980ed1 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -13,7 +13,7 @@ # REMOVE THIS BEFORE COPYING TO GITHUB! API_KEY = os.environ['OPENAI_KEY'] -client = OpenAI(api_key=API_KEY) #etest +client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') @@ -31,6 +31,7 @@ stroke = st.checkbox("Have you ever had a stroke?") diabetes = st.checkbox("Do you have a history of diabetes?") heart_attack = st.checkbox("Have you ever had a heart attack?") +ckd = st.checkbox("Do you have chronic kidney disease?") on_bp_meds = st.checkbox("Are you taking blood pressure medication?") systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) @@ -45,6 +46,7 @@ test_attributes["stroke"] = stroke test_attributes["diabetes"] = diabetes test_attributes["heart_attack"] = heart_attack + test_attributes["ckd"] = ckd test_attributes["on_BP_meds"] = on_bp_meds test_attributes["systolic_blood_pressure"] = systolic_bp #null or integer st.json(test_attributes) From 8e55f6f1fc26a1c9203ad53b557b7c7192169dfe Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:33:11 +0800 Subject: [PATCH 076/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 08a47b980ed1..ea8f41cb2420 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,7 +12,7 @@ from chatgpt_values import extract_values # REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['OPENAI_KEY'] +API_KEY = os.environ['API_KEY'] client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') From d95726a2c0ff5b07372798d2c80ae3f5f90b9540 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:35:09 +0800 Subject: [PATCH 077/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index ea8f41cb2420..f959667e719a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,7 +12,7 @@ from chatgpt_values import extract_values # REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['API_KEY'] +API_KEY = os.environ['OPENAI_KEY'] # it remembers the old API key but can't detect the new OPENAI secret :( client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') From 25b2cf31aa406a5cbf58d0fa01ac0fbef50cd1a9 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:37:51 +0800 Subject: [PATCH 078/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index f959667e719a..c1352441665f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,7 +12,7 @@ from chatgpt_values import extract_values # REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['OPENAI_KEY'] # it remembers the old API key but can't detect the new OPENAI secret :( +API_KEY = os.environ['API_KEY'] # it takes from streamlit secret client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') From b94249e0a8a9827f53a86ee77d28c124c4a50fcf Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:57:41 +0800 Subject: [PATCH 079/164] Update chatgpt_values.py --- chatgpt_values.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 8a2838907cd1..3415c4362764 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -9,6 +9,7 @@ from openai import OpenAI from paddleocr import PaddleOCR + template_prompt = """ Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". @@ -49,7 +50,7 @@ "test_ref_min":False, "test_ref_max":False }, - "rbc_count":{ + "rbc_count":{ "test_found":False, "test_value":False, "test_unit":False, @@ -103,7 +104,8 @@ Health screening result: """ -def extract_values(extracted_text): +def extract_values(client,extracted_text): + extract_start_time = time.time() extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( model="gpt-3.5-turbo-1106", @@ -114,4 +116,6 @@ def extract_values(extracted_text): ] ) test_results = json.loads(response.choices[0].message.content) - return response,test_results + extract_end_time = time.time() + extract_time = int(extract_end_time - extract_start_time) + return response,test_results,extract_time From c6794b3bccfe3ca52124cbd019ecf9ae305f9f37 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:58:41 +0800 Subject: [PATCH 080/164] Update image_loading.py --- image_loading.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/image_loading.py b/image_loading.py index 5e92396877eb..34df5196708f 100644 --- a/image_loading.py +++ b/image_loading.py @@ -9,7 +9,6 @@ from openai import OpenAI from paddleocr import PaddleOCR - def load_image(): uploaded_file = st.file_uploader(label='Upload your test results image below:') if uploaded_file is not None: @@ -19,10 +18,13 @@ def load_image(): def extract_text(image,ocr_model): + ocr_start_time = time.time() result = ocr_model.ocr(image) - result = result[0] #idk why this needs a result[0] instead of result for Github + #result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] extracted_text += txt + " " - return extracted_text + ocr_end_time = time.time() + ocr_time = int(ocr_end_time - ocr_start_time) + return extracted_text, ocr_time From cfd4a930c15b892a359647cbff91bd1970ae61fc Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:59:02 +0800 Subject: [PATCH 081/164] Update streamlit_app.py --- streamlit_app.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index c1352441665f..e4872a568c43 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,7 +12,8 @@ from chatgpt_values import extract_values # REMOVE THIS BEFORE COPYING TO GITHUB! -API_KEY = os.environ['API_KEY'] # it takes from streamlit secret +API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret + client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') @@ -49,28 +50,25 @@ test_attributes["ckd"] = ckd test_attributes["on_BP_meds"] = on_bp_meds test_attributes["systolic_blood_pressure"] = systolic_bp #null or integer - st.json(test_attributes) # Extract text from image if not image: #Image not uploaded st.error("Upload an image of your test results first!",icon="🚨") else: # Image uploaded - ocr_start_time = time.time() - extracted_text = extract_text(image,ocr_model) - ocr_end_time = time.time() - ocr_time = int(ocr_end_time - ocr_start_time) - st.markdown(extracted_text) - st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success - # Remove NRIC from extracted text - - # Extract structured data from text using ChatGPT - # TODO: PUT TRY AND ERROR IF FAIL - extract_start_time = time.time() - response,test_results = extract_values(client,extracted_text) # use chatgpt to extract - st.json(test_results) - st.text(response.usage) - extract_end_time = time.time() - extract_time = int(extract_end_time - extract_start_time) - st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success + with st.status('Reading image...', expanded=True) as status: + st.json(test_attributes) + extracted_text = extract_text(image,ocr_model,ocr_time) + st.markdown(extracted_text) + st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success + # Remove NRIC from extracted text + + # Extract structured data from text using ChatGPT + # TODO: PUT TRY AND ERROR IF FAIL + st.write("Extracting values from image...") + response,test_results,extract_time = extract_values(client,extracted_text) # use chatgpt to extract + st.json(test_results) + st.text(response.usage) + status.update(label="Analysed results!", state="complete", expanded=False) + st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success for test_name, test_info in test_results.items(): if test_info["test_found"]: st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") From 6d86eb152cd7b2fd96977a355add7b2d17c73139 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:00:43 +0800 Subject: [PATCH 082/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index e4872a568c43..a63ada656382 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -56,7 +56,7 @@ else: # Image uploaded with st.status('Reading image...', expanded=True) as status: st.json(test_attributes) - extracted_text = extract_text(image,ocr_model,ocr_time) + extracted_text,ocr_time = extract_text(image,ocr_model) st.markdown(extracted_text) st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success # Remove NRIC from extracted text From b579ee1727f51a2a564ea4be09776cb1060f67fd Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:03:07 +0800 Subject: [PATCH 083/164] Update image_loading.py --- image_loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_loading.py b/image_loading.py index 34df5196708f..9323f605100e 100644 --- a/image_loading.py +++ b/image_loading.py @@ -20,7 +20,7 @@ def load_image(): def extract_text(image,ocr_model): ocr_start_time = time.time() result = ocr_model.ocr(image) - #result = result[0] #idk why this needs a result[0] instead of result for Github + result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From ff41a91ae9eb6c841e913ca513a54cef669b07a6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:21:49 +0800 Subject: [PATCH 084/164] Update image_loading.py --- image_loading.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/image_loading.py b/image_loading.py index 9323f605100e..675fdeabb9be 100644 --- a/image_loading.py +++ b/image_loading.py @@ -6,6 +6,7 @@ import base64 import json import cv2 +import re from openai import OpenAI from paddleocr import PaddleOCR @@ -15,7 +16,11 @@ def load_image(): image_data = uploaded_file.getvalue() st.image(image_data, caption='', use_column_width=True) # Adjust width for mobile screens return image_data - + +def remove_nric(text): + pattern = r'[STFG]\d{7}[A-Z]' + replaced_text = re.sub(pattern, ' ', text) + return replaced_text def extract_text(image,ocr_model): ocr_start_time = time.time() @@ -25,6 +30,7 @@ def extract_text(image,ocr_model): for idx in range(len(result)): txt = result[idx][1][0] extracted_text += txt + " " + extracted_text_clean = remove_nric(extracted_text) ocr_end_time = time.time() ocr_time = int(ocr_end_time - ocr_start_time) - return extracted_text, ocr_time + return extracted_text_clean, ocr_time From 92bdcb6adfa09a0ad10e60b07f56548ac63b96ed Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:23:10 +0800 Subject: [PATCH 085/164] Delete .github/workflows directory --- .github/workflows/main.yml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 4fe8420e42f0..000000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Use OpenAI Secret - -on: [push] - -jobs: - access-secret: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v2 - - - name: Access OpenAI Key - run: echo "The secret is ${{ secrets.OPENAI_KEY }}" - env: - OPENAI_KEY: ${{ secrets.OPENAI_KEY }} From fed99b15e246de5fd99c913909578930b681b379 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 17:32:28 +0800 Subject: [PATCH 086/164] new anaemia and dm functions --- anaemia.py | 48 +++++++++++++++-- bmibp.py | 37 +++++++++++++ diabetes.py | 64 ++++++++++++++++++++++ lipids_ranges.py | 136 ++++++++++++++++++++++++++++++++--------------- refranges.py | 27 ++++------ 5 files changed, 248 insertions(+), 64 deletions(-) create mode 100644 bmibp.py create mode 100644 diabetes.py diff --git a/anaemia.py b/anaemia.py index 1414700a86ba..68018e9deabf 100644 --- a/anaemia.py +++ b/anaemia.py @@ -12,7 +12,7 @@ "test_unit":False, "test_ref_min":85, "test_ref_max":False - } + }, "hb":{ "test_found":True, "test_value":11, @@ -22,8 +22,46 @@ }, } #mcv need fl RBC need 10^6/uL +#returns tuple - bool whether anaemia, and bool whether iron deficient def anaemia_analysis (hbdict): - hblevel = hbdict["hb"]["test_value"] - anaemia = bool(hblevel < hbdict["hb"]["test_ref_min"]) - - return result \ No newline at end of file + hblevel = hbdict["hb"]["test_value"] + emergency = True if hblevel < 7 else False + mcv = hbdict["mcv"]["test_value"] + anaemia = bool(hblevel < hbdict["hb"]["test_ref_min"]) + antype = "" + iron = False + if anaemia: + if mcv < hbdict["mcv"]["test_ref_min"]: + mentzer = mcv/ hbdict["rbc_count"]["test_value"] + if mentzer > 13: + iron = True + else : + iron = False + antype = "microcytic" + elif mcv > hbdict["mcv"]["test_ref_max"]: + antype = "macrocytic" + else: + antype = "normocytic" + print(f"result of analysis {anaemia, antype, iron, emergency}\n") + return (anaemia, antype, iron, emergency) + +def get_anaemia_advice (input_tuple): + output_phrase = "" + (anaemia_bool, anaemia_type, iron_deficient, emerg) = input_tuple + if anaemia_bool: + if emerg == True: + output_phrase = "Your haemoglobin level is dangerously low. Please visit a doctor immediately." + elif anaemia_type == "microcytic": + if iron_deficient == True: + output_phrase = "you have anaemia, which could be due to iron deficiency. This can be caused by minor bleeding e.g. menstruation, or from the gastrointestinal tract. Visit your doctor for an assessment to rule out sources of bleeding. Consider taking iron supplements and foods rich in iron, such as green leafy vegetables, meat, especially red meat (beef, mutton, pork), seafood, and organs (kidney, liver)." + else: + output_phrase = "you have anaemia, which could be related to genetic conditions such as thalassaemia. Visit your doctor for an assessment." + elif anaemia_type == "macrocytic": + output_phrase = "you have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." + elif anaemia_type == "normocytic": + output_phrase = "you have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." + return output_phrase + +print (f"here is result: {get_anaemia_advice(anaemia_analysis (testdict))}") + + diff --git a/bmibp.py b/bmibp.py new file mode 100644 index 000000000000..9f20265cb08f --- /dev/null +++ b/bmibp.py @@ -0,0 +1,37 @@ +test_attributes = { + "systolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "diastolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "height":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "weight":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + } +} + + +def bmi_advice(weight, height): + + return output_string + +output = bmi_advice(test_attributes["weight"], test_attributes["height"]) \ No newline at end of file diff --git a/diabetes.py b/diabetes.py new file mode 100644 index 000000000000..bd3ba4b43ffa --- /dev/null +++ b/diabetes.py @@ -0,0 +1,64 @@ +testdict = { + "glucose":{ + "test_found":True, + "test_value":6.5, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "hba1c":{ + "test_found":True, + "test_value":6.4, + "test_unit":"%", + "test_ref_min":False, + "test_ref_max":False + } +} + +test_attributes = { + "age" : 40, + "sex" :"male", #0 for male, 1 for female + "smoker" : True, + "stroke" : False, + "diabetes" : True, + "ckd" : False + "heart_attack" : False , + "race" :"indian", + "systolic_blood_pressure" : 120, + "on_BP_meds" : False, + "total_cholesterol" : testdict["total_cholesterol"], #masterdict["CHOLESTEROL"] + "hdl_cholesterol" : testdict["hdl_cholesterol"] #masterdict["HDL CHOLESTEROL"] +} + + +def get_dm_advice(inputattributes, inputdict): + output_phrase = "" + lifestyle = False + #known dm + a1c_value = inputdict["hba1c"]["test_value"] + glucose_value = inputdict["glucose"]["test_value"] + targetdict = (8, 6.5, 7) + if inputattributes["age"] >= 80: + a1ctarget = 8 + elif inputattributes["age"] <=40: + a1ctarget = 6.5 + else: + a1ctarget = 7.0 + if a1c_value > a1ctarget: + output_phrase = "your HbA1c is above target, your diabetes can be controlled better." + lifestyle = True + else: + #diagnose dm + if a1c_value >= 6.5 or glucose_value >= 7: + output_phrase = "you have diabetes." + lifestyle = True + elif a1c_value >= 5.7 or glucose_value >=5.6: + output_phrase = "you have prediabetes." + lifestyle = True + else: + output_phrase = "you do not have diabetes." + if lifestyle: + output_phrase += "Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein, and half with fruit and vegetables). Maintain a healthy weight BMI ranging from 18.5 to 22.9 kg/m2. Exercise regularly, aiming for 150 minutes of moderate-intensity activity per week or 20 minutes of vigorous-intensity activity 3 or more days a week). Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + if inputattributes["smoker"]: + output_phrase += "Quit smoking." + return output_phrase \ No newline at end of file diff --git a/lipids_ranges.py b/lipids_ranges.py index f03ca7a47363..d143f746f0b3 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -1,34 +1,53 @@ -import json +#REMEMBER TO CHANGE BP TO TESTVALS +# import json +# # Open the file containing the JSON data +# with open('Sample json extraction\sample json extraction.txt') as f: +# # Load the JSON data from the file +# data = json.load(f) -# Open the file containing the JSON data -with open('Sample json extraction\sample json extraction.txt') as f: - # Load the JSON data from the file - data = json.load(f) - -# add data to a dictionary where key is test name and value is dictionary of test name/results etc. -masterdict = {} -# Access each individual object and list the attributes -for dict in data['test_results']: - masterdict [dict["test_name"]] = dict +# # add data to a dictionary where key is test name and value is dictionary of test name/results etc. +# masterdict = {} +# # Access each individual object and list the attributes +# for dict in data['test_results']: +# masterdict [dict["test_name"]] = dict testdict = { - "CHOLESTEROL": - { - "test_name": "CHOLESTEROL", - "test_value": 5.1, - "test_ref_min": "NA", - "test_ref_max": "NA", - "test_unit": "mmol/l" - }, - "HDL CHOLESTEROL": - { - "test_name": "HDL CHOLESTEROL", - "test_value": 1.6, - "test_ref_min": "NA", - "test_ref_max": "NA", - "test_unit": "mmol/l" - } + "ldl_cholesterol": { + "test_found":True, + "test_value":5.8, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "hdl_cholesterol": { + "test_found":True, + "test_value":1.0, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "total_cholesterol": { + "test_found":True, + "test_value":4.1, + "test_unit":"mmol/l", + "test_ref_min":False, + "test_ref_max":False + }, + "systolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "diastolic_bp":{ + "test_found":False, + "test_value":False, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, } @@ -37,24 +56,25 @@ #sample of attributes needed test_attributes = { - "age" : 35, + "age" : 40, "sex" :"male", #0 for male, 1 for female "smoker" : True, "stroke" : False, "diabetes" : False , + "ckd" : False, "heart_attack" : False , - "race" :"chinese", - "systolic_blood_pressure" : 140, + "race" :"indian", "on_BP_meds" : False, - "total_cholesterol" : testdict["CHOLESTEROL"], #masterdict["CHOLESTEROL"] - "hdl_cholesterol" : testdict["HDL CHOLESTEROL"] #masterdict["HDL CHOLESTEROL"] } -def getLDLtarget (attributes): +def getLDLtarget (attributes,testvals): if(attributes["stroke"]): return 1.8 - if(attributes["diabetes"]): - return 2.6 + if(attributes["diabetes"] or attributes["ckd"]): + if (attributes["diabetes"] and attributes["ckd"]): + return 1.8 + else: + return 2.6 if(attributes["heart_attack"]): return 1.4 #SGFRS scoring, only if no stroke or diabetes then proceed @@ -135,14 +155,14 @@ def getLDLtarget (attributes): score = 0 sex = 0 if attributes["sex"] == "male" else 1 age = attributes["age"] - tcval = attributes ["total_cholesterol"]["test_value"] - if attributes ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + tcval = testvals ["total_cholesterol"]["test_value"] + if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": if tcval > 280: cholbracket = 3 elif tcval > 240: cholbracket = 2 elif tcval > 200: cholbracket = 1 elif tcval > 160: cholbracket = 0 else: cholbracket = -1 - elif attributes ["total_cholesterol"]["test_unit"].lower() =="mmol/l": + elif testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": if tcval > 7.2: cholbracket = 3 elif tcval > 6.1: cholbracket = 2 elif tcval > 5.1: cholbracket = 1 @@ -218,10 +238,42 @@ def getLDLtarget (attributes): print (f"agescore {agescore} after smoking") score += agescore + match attributes["race"]: + case "indian": + raceint = 0 + case "malay": + raceint = 1 + case "chinese": + raceint = 2 +#matching to cardiovascular risk bracket + cvriskdict = { + ">20": ((16, 24), (17, 25), (19, 27)), + "10-20": ((12, 20), (14, 22), (16, 24)), + "5-10": ((9, 18), (11, 19), (13, 21)), + "<5": ((8, 17), (10, 18), (12, 20)), + } + recmeds = True + if score >= cvriskdict[">20"][raceint][sex]: + LDLtargetcalc = 1.8 + elif score >= cvriskdict["10-20"][raceint][sex]: + LDLtargetcalc = 2.6 + elif score >= cvriskdict["5-10"][raceint][sex]: + LDLtargetcalc = 3.4 + elif score <= cvriskdict["<5"][raceint][sex]: + LDLtargetcalc = 3.4 + recmeds = False - print (f"score {score}") - return LDLtarget + print (f"score {score} LDL target {LDLtargetcalc}") + if attributes ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: + output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10\% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + if recmeds: + output_phrase += "You may require cholesterol lowering medications, consult your doctor. " + if attributes["smoker"]: + output_phrase += "Quit smoking." + else: + output_phrase = "Your LDL cholesterol is within target range. Keep up the good work!" + return output_phrase + +print (f"advice is {getLDLtarget (test_attributes)}") -LDLtarget = getLDLtarget (test_attributes) -print (f"LDL target {LDLtarget}") diff --git a/refranges.py b/refranges.py index c77bf7defedc..89a6e6c0036b 100644 --- a/refranges.py +++ b/refranges.py @@ -4,21 +4,21 @@ testdict = { "ldl_cholesterol": { "test_found":True, - "test_value":20, + "test_value":2.0, "test_unit":"mmol/l", "test_ref_min":False, "test_ref_max":False }, "hdl_cholesterol": { "test_found":True, - "test_value":20, + "test_value":1.2, "test_unit":"mmol/l", "test_ref_min":False, "test_ref_max":False }, "total_cholesterol": { "test_found":True, - "test_value":20, + "test_value":5.0, "test_unit":"mmol/l", "test_ref_min":False, "test_ref_max":False @@ -44,7 +44,7 @@ "test_ref_min":False, "test_ref_max":False }, - "uric_acid":{ + "glucose":{ "test_found":False, "test_value":False, "test_unit":False, @@ -88,16 +88,9 @@ } } -test_attributes = { - "age" : 35, - "sex" :"male", #0 for male, 1 for female - "smoker" : True, - "stroke" : False, - "diabetes" : False , - "heart_attack" : False , - "race" :"chinese", - "systolic_blood_pressure" : 140, - "on_BP_meds" : False, - "total_cholesterol" : testdict["CHOLESTEROL"], #masterdict["CHOLESTEROL"] - "hdl_cholesterol" : testdict["HDL CHOLESTEROL"] #masterdict["HDL CHOLESTEROL"] -} \ No newline at end of file + +def bmi_advice(weight, height): + + return output_string + +output = bmi_advice(test_attributes["weight"], test_attributes["height"]) \ No newline at end of file From 06fa11f05cbbeb9c874281cb3cffb670efb35d02 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:49:04 +0800 Subject: [PATCH 087/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 3415c4362764..a7933aae8b18 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -11,7 +11,7 @@ template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres and weight to kg. Example output json template { From f25c8016b2b6db7950fb8ad4dd0adc8fca48f7cc Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:49:56 +0800 Subject: [PATCH 088/164] Update streamlit_app.py --- streamlit_app.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index a63ada656382..b56346540b9e 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -11,7 +11,6 @@ from image_loading import load_image, extract_text from chatgpt_values import extract_values -# REMOVE THIS BEFORE COPYING TO GITHUB! API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) @@ -20,9 +19,23 @@ test_attributes = {} +measurements_list = """ + - Height + - Weight + - Cholesterol + - Haemoglobin + - Mean Corpuscular Volume (MCV) + - Red Blood Cell (RBC) + - Glucose + - HbA1c + - Blood Pressure (BP) - systolic/diastolic +""" st.title('Explain my test results please!') +with st.sidebar as sidebar: + st.header('Lab measurements available') + st.markdown(measurements_list) st.header('Instructions') -st.markdown('Answer the questions, take a picture of your lab test results, upload it, and we will explain it to you!') +st.markdown('Answer the questions, take a picture of your lab test results, and get your results explained!') # User inputs age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") @@ -59,8 +72,6 @@ extracted_text,ocr_time = extract_text(image,ocr_model) st.markdown(extracted_text) st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success - # Remove NRIC from extracted text - # Extract structured data from text using ChatGPT # TODO: PUT TRY AND ERROR IF FAIL st.write("Extracting values from image...") @@ -73,8 +84,7 @@ if test_info["test_found"]: st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") - #st.markdown(f"**Reference Range:** {test_info['test_ref_min']} - {test_info['test_ref_max']} {test_info['test_unit']}") st.text("") # Insert YT logic -st.caption('Disclaimer: Not medical advice, not liable, blah') +st.caption('Disclaimer: Please be aware that the information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition. The use of any information provided on this app is solely at your own risk.') From a92997c5c02fa9fd073b36a450b859cae5b5bf22 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:06:17 +0800 Subject: [PATCH 089/164] Update streamlit_app.py --- streamlit_app.py | 118 +++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index b56346540b9e..e13391f666a3 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -17,6 +17,8 @@ ocr_model = PaddleOCR(use_angle_cls=True, lang='en') +tab1, tab2 = st.tabs(["Main", "More Info"]) + test_attributes = {} measurements_list = """ @@ -28,63 +30,67 @@ - Red Blood Cell (RBC) - Glucose - HbA1c - - Blood Pressure (BP) - systolic/diastolic + - Blood Pressure (BP) """ -st.title('Explain my test results please!') -with st.sidebar as sidebar: - st.header('Lab measurements available') - st.markdown(measurements_list) -st.header('Instructions') -st.markdown('Answer the questions, take a picture of your lab test results, and get your results explained!') - -# User inputs -age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") -sex = st.selectbox("Select your sex", ["Female","Male"]) -race = st.selectbox("Select your race", ["Chinese", "Malay", "Indian", "Others"]) -smoker = st.checkbox("Are you a smoker?") -stroke = st.checkbox("Have you ever had a stroke?") -diabetes = st.checkbox("Do you have a history of diabetes?") -heart_attack = st.checkbox("Have you ever had a heart attack?") -ckd = st.checkbox("Do you have chronic kidney disease?") -on_bp_meds = st.checkbox("Are you taking blood pressure medication?") -systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) + +with tab1: + st.title('Explain my test results please!') + st.subheader('Answer the questions, take a picture of your lab test results, and get your results explained!') + + # User inputs + age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") + sex = st.selectbox("Select your sex", ["Female","Male"]) + race = st.selectbox("Select your race", ["Chinese", "Malay", "Indian", "Others"]) + smoker = st.checkbox("Are you a smoker?") + stroke = st.checkbox("Have you ever had a stroke?") + diabetes = st.checkbox("Do you have a history of diabetes?") + heart_attack = st.checkbox("Have you ever had a heart attack?") + ckd = st.checkbox("Do you have chronic kidney disease?") + on_bp_meds = st.checkbox("Are you taking blood pressure medication?") + systolic_bp = st.number_input("Enter your last recorded systolic blood pressure (leave blank if not available)", min_value=50,max_value=300,value=None) + + image = load_image() -image = load_image() + if st.button('Analyse my results'): + # Save test attributes + test_attributes["age"] = age + test_attributes["sex"] = sex + test_attributes["race"] = race + test_attributes["smoker"] = smoker #true or false + test_attributes["stroke"] = stroke + test_attributes["diabetes"] = diabetes + test_attributes["heart_attack"] = heart_attack + test_attributes["ckd"] = ckd + test_attributes["on_BP_meds"] = on_bp_meds + test_attributes["systolic_blood_pressure"] = systolic_bp #null or integer + # Extract text from image + if not image: #Image not uploaded + st.error("Upload an image of your test results first!",icon="🚨") + else: # Image uploaded + with st.status('Reading image...', expanded=True) as status: + st.json(test_attributes) + extracted_text,ocr_time = extract_text(image,ocr_model) + st.markdown(extracted_text) + st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success + # Extract structured data from text using ChatGPT + # TODO: PUT TRY AND ERROR IF FAIL + st.write("Extracting values from image...") + response,test_results,extract_time = extract_values(client,extracted_text) # use chatgpt to extract + st.json(test_results) + st.text(response.usage) + status.update(label="Analysed results!", state="complete", expanded=False) + st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success + for test_name, test_info in test_results.items(): + if test_info["test_found"]: + st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") + st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") + st.text("") + # Insert YT logic + + +with tab2: + st.header('Lab measurements included for analysis') + st.markdown(measurements_list) + st.write('Other lab tests will be added soon...stay tuned!') -if st.button('Analyse my results'): - # Save test attributes - test_attributes["age"] = age - test_attributes["sex"] = sex - test_attributes["race"] = race - test_attributes["smoker"] = smoker #true or false - test_attributes["stroke"] = stroke - test_attributes["diabetes"] = diabetes - test_attributes["heart_attack"] = heart_attack - test_attributes["ckd"] = ckd - test_attributes["on_BP_meds"] = on_bp_meds - test_attributes["systolic_blood_pressure"] = systolic_bp #null or integer - # Extract text from image - if not image: #Image not uploaded - st.error("Upload an image of your test results first!",icon="🚨") - else: # Image uploaded - with st.status('Reading image...', expanded=True) as status: - st.json(test_attributes) - extracted_text,ocr_time = extract_text(image,ocr_model) - st.markdown(extracted_text) - st.success(f"Processed image in {ocr_time} seconds.") # Use status instead of toast/success - # Extract structured data from text using ChatGPT - # TODO: PUT TRY AND ERROR IF FAIL - st.write("Extracting values from image...") - response,test_results,extract_time = extract_values(client,extracted_text) # use chatgpt to extract - st.json(test_results) - st.text(response.usage) - status.update(label="Analysed results!", state="complete", expanded=False) - st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success - for test_name, test_info in test_results.items(): - if test_info["test_found"]: - st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") - st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") - st.text("") - # Insert YT logic - st.caption('Disclaimer: Please be aware that the information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition. The use of any information provided on this app is solely at your own risk.') From 06ce1996f1c723f27701fc0024073b3f069fde4e Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:07:28 +0800 Subject: [PATCH 090/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index e13391f666a3..014ce4b74667 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -93,4 +93,4 @@ st.markdown(measurements_list) st.write('Other lab tests will be added soon...stay tuned!') -st.caption('Disclaimer: Please be aware that the information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition. The use of any information provided on this app is solely at your own risk.') +st.caption('Disclaimer: Information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition. The use of any information provided on this app is solely at your own risk.') From 2f999d2196bf51512af1bb3369cf8f3e5c48ba0a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:08:06 +0800 Subject: [PATCH 091/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 014ce4b74667..a38d6274e54c 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -93,4 +93,4 @@ st.markdown(measurements_list) st.write('Other lab tests will be added soon...stay tuned!') -st.caption('Disclaimer: Information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition. The use of any information provided on this app is solely at your own risk.') +st.caption('Disclaimer: Information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.') From ef91bf91af7c51d43f3b554a815e264173ac4ce7 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:09:38 +0800 Subject: [PATCH 092/164] add new calculators --- bmi.py | 36 +++++ bmibp.py | 37 ----- lipids_ranges.py | 383 ++++++++++++++++++++++++----------------------- refranges.py | 7 +- 4 files changed, 236 insertions(+), 227 deletions(-) create mode 100644 bmi.py delete mode 100644 bmibp.py diff --git a/bmi.py b/bmi.py new file mode 100644 index 000000000000..670eeaf91daf --- /dev/null +++ b/bmi.py @@ -0,0 +1,36 @@ +test_attributes = { + "height":{ + "test_found":False, + "test_value":1.5, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + }, + "weight":{ + "test_found":False, + "test_value":70, + "test_unit":False, + "test_ref_min":False, + "test_ref_max":False + } +} + + +def bmi_advice(weight, height): + bmi = weight / pow(height,2) + weightloss = False + if bmi >=27.5: + output_string = "You are obese. " + weightloss = True + elif bmi >= 23: + output_string = "You are overweight. " + weightloss = True + elif bmi < 18.5: + output_string = "You are underweight. Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." + else: + output_string = "You have a healthy BMI." + if weightloss: + output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." + return output_string + +print ("advice " + bmi_advice(test_attributes["weight"]["test_value"], test_attributes["height"]["test_value"])) \ No newline at end of file diff --git a/bmibp.py b/bmibp.py deleted file mode 100644 index 9f20265cb08f..000000000000 --- a/bmibp.py +++ /dev/null @@ -1,37 +0,0 @@ -test_attributes = { - "systolic_bp":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "diastolic_bp":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "height":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - }, - "weight":{ - "test_found":False, - "test_value":False, - "test_unit":False, - "test_ref_min":False, - "test_ref_max":False - } -} - - -def bmi_advice(weight, height): - - return output_string - -output = bmi_advice(test_attributes["weight"], test_attributes["height"]) \ No newline at end of file diff --git a/lipids_ranges.py b/lipids_ranges.py index d143f746f0b3..f9a42d375ac4 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -68,212 +68,225 @@ } def getLDLtarget (attributes,testvals): + LDLtargetcalc = 0 + BP_target = (0, 0) if(attributes["stroke"]): - return 1.8 + LDLtargetcalc = 1.8 + BP_target = (140, 90) #with disclaimer if(attributes["diabetes"] or attributes["ckd"]): + BP_target = (130, 80) if (attributes["diabetes"] and attributes["ckd"]): - return 1.8 + LDLtargetcalc = 1.8 else: - return 2.6 + LDLtargetcalc = 2.6 if(attributes["heart_attack"]): - return 1.4 + LDLtargetcalc = 1.4 #SGFRS scoring, only if no stroke or diabetes then proceed - LDLtarget = 0 - #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 - # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score - # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; - # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 - agedict = { - 20 : { - "age": ( - (-9, -7), #20-34 (M, F) - (-4, -3)), #35-39 (M, F)) - "tchol": ( - (4, 4), #4.1-5.1 (M, F) - (7, 8), #5.2-6.1 (M, F) - (9, 11), #6.2-7.2 (M, F) - (11, 13)),#>=7.3 (M, F) - "smoker": (8, 9) - }, - 40 :{ - "age": (( - 0, 0), - (3, 3)), - "tchol" : ( - (3, 3), - (5, 6), - (6, 8), - (8, 10)), - "smoker": (5, 7) - }, - 50 :{ - "age": ( - (6, 6), - (8, 8)), - "tchol" : ( - (2, 2), - (3, 4), - (4, 5), - (5, 7)), - "smoker": (3, 4) - }, - 60 :{ - "age": ( - (10, 10), - (11, 12)), - "tchol" : ( - (1, 1), - (1, 2), - (2, 3), - (3, 4)), - "smoker": (1, 2) - }, - 70 :{ - "age": ( - (12, 14), - (13, 16)), - "tchol" : ( - (0, 1), - (0, 1), - (1, 2), - (1, 2)), - "smoker": (1, 1) + if LDLtargetcalc == 0: + #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 + # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score + # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; + # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 + agedict = { + 20 : { + "age": ( + (-9, -7), #20-34 (M, F) + (-4, -3)), #35-39 (M, F)) + "tchol": ( + (4, 4), #4.1-5.1 (M, F) + (7, 8), #5.2-6.1 (M, F) + (9, 11), #6.2-7.2 (M, F) + (11, 13)),#>=7.3 (M, F) + "smoker": (8, 9) + }, + 40 :{ + "age": (( + 0, 0), + (3, 3)), + "tchol" : ( + (3, 3), + (5, 6), + (6, 8), + (8, 10)), + "smoker": (5, 7) + }, + 50 :{ + "age": ( + (6, 6), + (8, 8)), + "tchol" : ( + (2, 2), + (3, 4), + (4, 5), + (5, 7)), + "smoker": (3, 4) + }, + 60 :{ + "age": ( + (10, 10), + (11, 12)), + "tchol" : ( + (1, 1), + (1, 2), + (2, 3), + (3, 4)), + "smoker": (1, 2) + }, + 70 :{ + "age": ( + (12, 14), + (13, 16)), + "tchol" : ( + (0, 1), + (0, 1), + (1, 2), + (1, 2)), + "smoker": (1, 1) + } + } + #dictionary corresponding to ageless variables + otherriskdict = { + "hdl" : (-1, 0, 1, 2), #regardless of gender, for ranges >=1.6, 1.3-1.5, 1.0-1.2, <1.0 + "sysBP" : ( + ((0, 1),(1, 3)), #untreated M, F , treated M, F for 120-129 + ((1, 2),(2, 4)), #130-139 + ((1, 3),(2, 5)), #140-159 + ((2, 4),(3, 6)), #>160 + ) } - } - #dictionary corresponding to ageless variables - otherriskdict = { - "hdl" : (-1, 0, 1, 2), #regardless of gender, for ranges >=1.6, 1.3-1.5, 1.0-1.2, <1.0 - "sysBP" : ( - ((0, 1),(1, 3)), #untreated M, F , treated M, F for 120-129 - ((1, 2),(2, 4)), #130-139 - ((1, 3),(2, 5)), #140-159 - ((2, 4),(3, 6)), #>160 - ) - } - #start scoring - print (f"scoring now") - score = 0 - sex = 0 if attributes["sex"] == "male" else 1 - age = attributes["age"] - tcval = testvals ["total_cholesterol"]["test_value"] - if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": - if tcval > 280: cholbracket = 3 - elif tcval > 240: cholbracket = 2 - elif tcval > 200: cholbracket = 1 - elif tcval > 160: cholbracket = 0 - else: cholbracket = -1 - elif testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": - if tcval > 7.2: cholbracket = 3 - elif tcval > 6.1: cholbracket = 2 - elif tcval > 5.1: cholbracket = 1 - elif tcval > 4.1: cholbracket = 0 - else: cholbracket = -1 - else: - cholbracket = -1 - print ("invalid cholesterol units") + #start scoring + print (f"scoring now") + score = 0 + sex = 0 if attributes["sex"] == "male" else 1 + age = attributes["age"] + tcval = testvals ["total_cholesterol"]["test_value"] + if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + if tcval > 280: cholbracket = 3 + elif tcval > 240: cholbracket = 2 + elif tcval > 200: cholbracket = 1 + elif tcval > 160: cholbracket = 0 + else: cholbracket = -1 + elif testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": + if tcval > 7.2: cholbracket = 3 + elif tcval > 6.1: cholbracket = 2 + elif tcval > 5.1: cholbracket = 1 + elif tcval > 4.1: cholbracket = 0 + else: cholbracket = -1 + else: + cholbracket = -1 + print ("invalid cholesterol units") - hval = attributes ["hdl_cholesterol"]["test_value"] - if attributes ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": - if hval > 59: hdlbracket = 0 - elif hval > 49: hdlbracket = 1 - elif hval > 40: hdlbracket = 2 - else: hdlbracket = 3 - if attributes ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": - if hval > 1.5: hdlbracket = 0 - elif hval > 1.2: hdlbracket = 1 - elif hval > 1: hdlbracket = 2 - else: hdlbracket = 3 - else: - hdlbracket = -1 - print ("invalid cholesterol units") + hval = testvals ["hdl_cholesterol"]["test_value"] + if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + if hval > 59: hdlbracket = 0 + elif hval > 49: hdlbracket = 1 + elif hval > 40: hdlbracket = 2 + else: hdlbracket = 3 + if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": + if hval > 1.5: hdlbracket = 0 + elif hval > 1.2: hdlbracket = 1 + elif hval > 1: hdlbracket = 2 + else: hdlbracket = 3 + else: + hdlbracket = -1 + print ("invalid cholesterol units") - bval = attributes ["systolic_blood_pressure"] - if bval > 159: bpbracket = 3 - elif bval > 139: bpbracket = 2 - elif bval > 129: bpbracket = 1 - elif bval > 119: bpbracket = 0 - else: bpbracket = -1 + bval = testvals ["systolic_bp"]["test_value"] + if bval > 159: bpbracket = 3 + elif bval > 139: bpbracket = 2 + elif bval > 129: bpbracket = 1 + elif bval > 119: bpbracket = 0 + else: bpbracket = -1 - # HDL points - if hdlbracket >-1: - score += otherriskdict["hdl"][hdlbracket] + # HDL points + if hdlbracket >-1: + score += otherriskdict["hdl"][hdlbracket] - #systolic BP points - treated = 1 if attributes["on_BP_meds"] else 0 - if bpbracket > -1: - score += otherriskdict["sysBP"][bpbracket][treated][sex] - print (f"score after BP/hdl {score}") - agescore = 0 - if age >70: - curdict = agedict[70] - agebracket = 0 if age <75 else 1 - elif age >60: - curdict = agedict[60] - agebracket = 0 if age <65 else 1 - elif age >50: - curdict = agedict[50] - agebracket = 0 if age <55 else 1 - elif age >40: - curdict = agedict[40] - agebracket = 0 if age <45 else 1 - elif age >20: - curdict = agedict[20] - agebracket = 0 if age <35 else 1 - else: - print ("you are too young to use this calculator") - return 0 + #systolic BP points + treated = 1 if attributes["on_BP_meds"] else 0 + if bpbracket > -1: + score += otherriskdict["sysBP"][bpbracket][treated][sex] + print (f"score after BP/hdl {score}") + agescore = 0 + if age >70: + curdict = agedict[70] + agebracket = 0 if age <75 else 1 + if age >80: + BP_target = (150, 90) + elif age >60: + curdict = agedict[60] + agebracket = 0 if age <65 else 1 + elif age >50: + curdict = agedict[50] + agebracket = 0 if age <55 else 1 + elif age >40: + curdict = agedict[40] + agebracket = 0 if age <45 else 1 + elif age >20: + curdict = agedict[20] + agebracket = 0 if age <35 else 1 + else: + print ("you are too young to use this calculator") + return 0 - # age only points - agescore += curdict["age"][agebracket][sex] - print (f"agescore {agescore} after age only") + # age only points + agescore += curdict["age"][agebracket][sex] + print (f"agescore {agescore} after age only") - # age and cholesterol points - if cholbracket > -1: #no points if cholesterol is <4.1 - agescore += curdict["tchol"][cholbracket][sex] - print (f"agescore {agescore} after chol") + # age and cholesterol points + if cholbracket > -1: #no points if cholesterol is <4.1 + agescore += curdict["tchol"][cholbracket][sex] + print (f"agescore {agescore} after chol") - # age and smoking points - if attributes["smoker"]: - agescore += curdict["smoker"][sex] - print (f"agescore {agescore} after smoking") + # age and smoking points + if attributes["smoker"]: + agescore += curdict["smoker"][sex] + print (f"agescore {agescore} after smoking") - score += agescore - match attributes["race"]: - case "indian": - raceint = 0 - case "malay": - raceint = 1 - case "chinese": - raceint = 2 + score += agescore + match attributes["race"]: + case "indian": + raceint = 0 + case "malay": + raceint = 1 + case "chinese": + raceint = 2 -#matching to cardiovascular risk bracket - cvriskdict = { - ">20": ((16, 24), (17, 25), (19, 27)), - "10-20": ((12, 20), (14, 22), (16, 24)), - "5-10": ((9, 18), (11, 19), (13, 21)), - "<5": ((8, 17), (10, 18), (12, 20)), - } - recmeds = True - if score >= cvriskdict[">20"][raceint][sex]: - LDLtargetcalc = 1.8 - elif score >= cvriskdict["10-20"][raceint][sex]: - LDLtargetcalc = 2.6 - elif score >= cvriskdict["5-10"][raceint][sex]: - LDLtargetcalc = 3.4 - elif score <= cvriskdict["<5"][raceint][sex]: - LDLtargetcalc = 3.4 - recmeds = False + #matching to cardiovascular risk bracket + cvriskdict = { + ">20": ((16, 24), (17, 25), (19, 27)), + "10-20": ((12, 20), (14, 22), (16, 24)), + "5-10": ((9, 18), (11, 19), (13, 21)), + "<5": ((8, 17), (10, 18), (12, 20)), + } + recmeds = True + if score >= cvriskdict[">20"][raceint][sex]: + LDLtargetcalc = 1.8 + BP_target = (130, 80) + elif score >= cvriskdict["10-20"][raceint][sex]: + LDLtargetcalc = 2.6 + elif score >= cvriskdict["5-10"][raceint][sex]: + LDLtargetcalc = 3.4 + elif score <= cvriskdict["<5"][raceint][sex]: + LDLtargetcalc = 3.4 + recmeds = False print (f"score {score} LDL target {LDLtargetcalc}") - if attributes ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: - output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10\% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + if testvals ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: + output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if recmeds: output_phrase += "You may require cholesterol lowering medications, consult your doctor. " - if attributes["smoker"]: - output_phrase += "Quit smoking." + else: - output_phrase = "Your LDL cholesterol is within target range. Keep up the good work!" + output_phrase = "Your LDL cholesterol is within target range." + if testvals["systolic _bp"] > BP_target[0] or testvals["diastolic _bp"] > BP_target[1]: + output_phrase += "\n Your blood pressure is high. Your target should be " + BP_target[0] + "/" + BP_target[1] + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." + if attributes["stroke"]: + output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." + if attributes["smoker"]: + output_phrase += "\nQuit smoking." return output_phrase -print (f"advice is {getLDLtarget (test_attributes)}") +print (f"advice is {getLDLtarget (test_attributes, testdict)}") + diff --git a/refranges.py b/refranges.py index 89a6e6c0036b..88a889b161bb 100644 --- a/refranges.py +++ b/refranges.py @@ -1,5 +1,7 @@ import json from lipids_ranges import getLDLtarget +from diabetes import get_dm_advice +from anaemia import anaemia_analysis, get_anaemia_advice testdict = { "ldl_cholesterol": { @@ -89,8 +91,3 @@ } -def bmi_advice(weight, height): - - return output_string - -output = bmi_advice(test_attributes["weight"], test_attributes["height"]) \ No newline at end of file From d9e4a21fa54e0c5cee372b862471545d7603305b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:42:39 +0800 Subject: [PATCH 093/164] integrated to streamlit --- bmi.py | 8 +++++--- diabetes.py | 40 ++++++++++++++++++++++++---------------- lipids_ranges.py | 25 +++++++++++++++---------- streamlit_app.py | 22 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 29 deletions(-) diff --git a/bmi.py b/bmi.py index 670eeaf91daf..35a4f298d5e9 100644 --- a/bmi.py +++ b/bmi.py @@ -1,4 +1,4 @@ -test_attributes = { +test_results = { "height":{ "test_found":False, "test_value":1.5, @@ -16,7 +16,9 @@ } -def bmi_advice(weight, height): +def bmi_advice(test_results): + weight = test_results["weight"]["test_value"] + height = test_results["height"]["test_value"] bmi = weight / pow(height,2) weightloss = False if bmi >=27.5: @@ -33,4 +35,4 @@ def bmi_advice(weight, height): output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string -print ("advice " + bmi_advice(test_attributes["weight"]["test_value"], test_attributes["height"]["test_value"])) \ No newline at end of file +print ("advice " + bmi_advice(test_results)) \ No newline at end of file diff --git a/diabetes.py b/diabetes.py index bd3ba4b43ffa..fb61cd82633e 100644 --- a/diabetes.py +++ b/diabetes.py @@ -21,13 +21,11 @@ "smoker" : True, "stroke" : False, "diabetes" : True, - "ckd" : False + "ckd" : False, "heart_attack" : False , "race" :"indian", "systolic_blood_pressure" : 120, - "on_BP_meds" : False, - "total_cholesterol" : testdict["total_cholesterol"], #masterdict["CHOLESTEROL"] - "hdl_cholesterol" : testdict["hdl_cholesterol"] #masterdict["HDL CHOLESTEROL"] + "on_BP_meds" : False } @@ -37,20 +35,28 @@ def get_dm_advice(inputattributes, inputdict): #known dm a1c_value = inputdict["hba1c"]["test_value"] glucose_value = inputdict["glucose"]["test_value"] - targetdict = (8, 6.5, 7) - if inputattributes["age"] >= 80: - a1ctarget = 8 - elif inputattributes["age"] <=40: - a1ctarget = 6.5 - else: - a1ctarget = 7.0 - if a1c_value > a1ctarget: - output_phrase = "your HbA1c is above target, your diabetes can be controlled better." - lifestyle = True + if inputattributes["diabetes"]: + if inputdict["hba1c"]["test_found"]: + if inputattributes["age"] >= 80: + a1ctarget = 8 + elif inputattributes["age"] <=40: + a1ctarget = 6.5 + else: + a1ctarget = 7.0 + if a1c_value > a1ctarget: + output_phrase = "your HbA1c is above target, your diabetes can be controlled better." + lifestyle = True + else: + output_phrase = "your HbA1c is within range." + else: + if glucose_value > 6: + output_phrase += "\nyour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." + else: + output_phrase += "\nyour fasting glucose level is within range." else: #diagnose dm if a1c_value >= 6.5 or glucose_value >= 7: - output_phrase = "you have diabetes." + output_phrase = "you have diabetes. Consult a doctor for advice, you may need to be started on medications." lifestyle = True elif a1c_value >= 5.7 or glucose_value >=5.6: output_phrase = "you have prediabetes." @@ -61,4 +67,6 @@ def get_dm_advice(inputattributes, inputdict): output_phrase += "Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein, and half with fruit and vegetables). Maintain a healthy weight BMI ranging from 18.5 to 22.9 kg/m2. Exercise regularly, aiming for 150 minutes of moderate-intensity activity per week or 20 minutes of vigorous-intensity activity 3 or more days a week). Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if inputattributes["smoker"]: output_phrase += "Quit smoking." - return output_phrase \ No newline at end of file + return output_phrase + +print(f"advice {get_dm_advice(test_attributes, testdict)}") \ No newline at end of file diff --git a/lipids_ranges.py b/lipids_ranges.py index f9a42d375ac4..c03a2a3ab3fc 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -35,15 +35,15 @@ "test_ref_max":False }, "systolic_bp":{ - "test_found":False, - "test_value":False, + "test_found":True, + "test_value":200, "test_unit":False, "test_ref_min":False, "test_ref_max":False }, "diastolic_bp":{ - "test_found":False, - "test_value":False, + "test_found":True, + "test_value":100, "test_unit":False, "test_ref_min":False, "test_ref_max":False @@ -67,7 +67,7 @@ "on_BP_meds" : False, } -def getLDLtarget (attributes,testvals): +def getLDLBPtarget (attributes,testvals): LDLtargetcalc = 0 BP_target = (0, 0) if(attributes["stroke"]): @@ -279,14 +279,19 @@ def getLDLtarget (attributes,testvals): else: output_phrase = "Your LDL cholesterol is within target range." - if testvals["systolic _bp"] > BP_target[0] or testvals["diastolic _bp"] > BP_target[1]: - output_phrase += "\n Your blood pressure is high. Your target should be " + BP_target[0] + "/" + BP_target[1] + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." - if attributes["stroke"]: - output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." + if testvals["systolic_bp"]["test_found"]: + bp = (testvals["systolic _bp"]["test_value"], testvals["diastolic _bp"]["test_value"]) + if bp[0] > BP_target[0] or bp[1] > BP_target[1]: + if bp[0] > 180 or bp[1] > 120: + output_phrase += " \n Your blood pressure is dangerously high. Visit a doctor for assessment.\n" + else: + output_phrase += "\n Your blood pressure is high. Your target should be " + BP_target[0] + "/" + BP_target[1] + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." + if attributes["stroke"]: + output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." if attributes["smoker"]: output_phrase += "\nQuit smoking." return output_phrase -print (f"advice is {getLDLtarget (test_attributes, testdict)}") +print (f"advice is {getLDLBPtarget (test_attributes, testdict)}") diff --git a/streamlit_app.py b/streamlit_app.py index a38d6274e54c..c31724d68b08 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -10,6 +10,10 @@ from paddleocr import PaddleOCR from image_loading import load_image, extract_text from chatgpt_values import extract_values +from lipids_ranges import getLDLBPtarget +from diabetes import get_dm_advice +from anaemia import anaemia_analysis, get_anaemia_advice +from bmi import bmi_advice API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret @@ -86,6 +90,24 @@ st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") st.text("") # Insert YT logic + #test_results test_attributes + for key, value in test_results.iter(): + if value["test_found"]: + if key == "mcv": + st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") + elif key == "ldl_cholesterol": + st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") + elif key == "glucose": + st.write (f"LDL/BP {get_dm_advice(test_attributes, test_results)}") + elif key == "systolic_bp": + if not test_results["ldl_cholesterol"]["test_found"]: + st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") + elif key == "weight": + st.write (f"BMI {bmi_advice(test_results)}") + + + + with tab2: From 43bba3309ae7bb0d242eee4c1f7bf5bd20f4cd67 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:51:34 +0800 Subject: [PATCH 094/164] change to elif --- lipids_ranges.py | 13 ++++++------- streamlit_app.py | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index c03a2a3ab3fc..c7c710515eac 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -244,13 +244,12 @@ def getLDLBPtarget (attributes,testvals): print (f"agescore {agescore} after smoking") score += agescore - match attributes["race"]: - case "indian": - raceint = 0 - case "malay": - raceint = 1 - case "chinese": - raceint = 2 + if attributes["race"] == "indian": + raceint = 0 + elif attributes["race"] == "malay": + raceint = 1 + elif attributes["race"] == "chinese": + raceint = 2 #matching to cardiovascular risk bracket cvriskdict = { diff --git a/streamlit_app.py b/streamlit_app.py index c31724d68b08..7aee4fe0cbba 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -103,7 +103,8 @@ if not test_results["ldl_cholesterol"]["test_found"]: st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") elif key == "weight": - st.write (f"BMI {bmi_advice(test_results)}") + st.write (f"BMI {bmi_advice(test_results)}") + From 3f8b42d6b2a168f483364afef2c9f2aaf0e8c92b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:52:38 +0800 Subject: [PATCH 095/164] remove space --- lipids_ranges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index c7c710515eac..07c77486c191 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -279,7 +279,7 @@ def getLDLBPtarget (attributes,testvals): else: output_phrase = "Your LDL cholesterol is within target range." if testvals["systolic_bp"]["test_found"]: - bp = (testvals["systolic _bp"]["test_value"], testvals["diastolic _bp"]["test_value"]) + bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic _bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: if bp[0] > 180 or bp[1] > 120: output_phrase += " \n Your blood pressure is dangerously high. Visit a doctor for assessment.\n" From c7006c2afe431b4326116e01056317ac9421043b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:54:11 +0800 Subject: [PATCH 096/164] remove space 2 --- lipids_ranges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 07c77486c191..889005d5308c 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -279,7 +279,7 @@ def getLDLBPtarget (attributes,testvals): else: output_phrase = "Your LDL cholesterol is within target range." if testvals["systolic_bp"]["test_found"]: - bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic _bp"]["test_value"]) + bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic_bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: if bp[0] > 180 or bp[1] > 120: output_phrase += " \n Your blood pressure is dangerously high. Visit a doctor for assessment.\n" From 0a2e5681336e39420ac9514ba18697259af5ca40 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:56:10 +0800 Subject: [PATCH 097/164] iteritems --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 7aee4fe0cbba..070ffcc5eec7 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -91,7 +91,7 @@ st.text("") # Insert YT logic #test_results test_attributes - for key, value in test_results.iter(): + for key, value in test_results.items(): if value["test_found"]: if key == "mcv": st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") From eeb3e10f7153fd5bcdc8d1596618cef5b91b53cd Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 20:58:59 +0800 Subject: [PATCH 098/164] print --- lipids_ranges.py | 2 +- streamlit_app.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 889005d5308c..cce9f659a0a6 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -270,7 +270,7 @@ def getLDLBPtarget (attributes,testvals): LDLtargetcalc = 3.4 recmeds = False - print (f"score {score} LDL target {LDLtargetcalc}") + #print (f"score {score} LDL target {LDLtargetcalc}") if testvals ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if recmeds: diff --git a/streamlit_app.py b/streamlit_app.py index 070ffcc5eec7..aa0c9e9fe558 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -94,11 +94,14 @@ for key, value in test_results.items(): if value["test_found"]: if key == "mcv": + print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") elif key == "ldl_cholesterol": st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") + print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") elif key == "glucose": st.write (f"LDL/BP {get_dm_advice(test_attributes, test_results)}") + print (f"LDL/BP {get_dm_advice(test_attributes, test_results)}") elif key == "systolic_bp": if not test_results["ldl_cholesterol"]["test_found"]: st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") From d1b8f5f2a53b903b13de84554ca776cf186e51e0 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:02:05 +0800 Subject: [PATCH 099/164] uncomment print --- lipids_ranges.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index cce9f659a0a6..991be250d668 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -68,6 +68,7 @@ } def getLDLBPtarget (attributes,testvals): + print ("in ldl target") LDLtargetcalc = 0 BP_target = (0, 0) if(attributes["stroke"]): @@ -155,7 +156,7 @@ def getLDLBPtarget (attributes,testvals): ) } #start scoring - print (f"scoring now") + #print (f"scoring now") score = 0 sex = 0 if attributes["sex"] == "male" else 1 age = attributes["age"] @@ -231,17 +232,17 @@ def getLDLBPtarget (attributes,testvals): # age only points agescore += curdict["age"][agebracket][sex] - print (f"agescore {agescore} after age only") + #print (f"agescore {agescore} after age only") # age and cholesterol points if cholbracket > -1: #no points if cholesterol is <4.1 agescore += curdict["tchol"][cholbracket][sex] - print (f"agescore {agescore} after chol") + #print (f"agescore {agescore} after chol") # age and smoking points if attributes["smoker"]: agescore += curdict["smoker"][sex] - print (f"agescore {agescore} after smoking") + #print (f"agescore {agescore} after smoking") score += agescore if attributes["race"] == "indian": @@ -291,6 +292,6 @@ def getLDLBPtarget (attributes,testvals): output_phrase += "\nQuit smoking." return output_phrase -print (f"advice is {getLDLBPtarget (test_attributes, testdict)}") +#print (f"advice is {getLDLBPtarget (test_attributes, testdict)}") From 2f22c171a73dcb374c7ca2ec6c2097deb8f3ca3b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:04:49 +0800 Subject: [PATCH 100/164] more comment --- streamlit_app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/streamlit_app.py b/streamlit_app.py index aa0c9e9fe558..6acc79744786 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -92,6 +92,7 @@ # Insert YT logic #test_results test_attributes for key, value in test_results.items(): + print ("looking at {key} and {value}") if value["test_found"]: if key == "mcv": print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") From 1dfccfe8370390bdb9d497f1a8a9b135b3d2a44a Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:05:28 +0800 Subject: [PATCH 101/164] remove useless print --- anaemia.py | 4 +++- bmi.py | 3 ++- diabetes.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/anaemia.py b/anaemia.py index 68018e9deabf..8b9023c2ee58 100644 --- a/anaemia.py +++ b/anaemia.py @@ -24,6 +24,7 @@ #mcv need fl RBC need 10^6/uL #returns tuple - bool whether anaemia, and bool whether iron deficient def anaemia_analysis (hbdict): + print ("in anaemia analysis") hblevel = hbdict["hb"]["test_value"] emergency = True if hblevel < 7 else False mcv = hbdict["mcv"]["test_value"] @@ -46,6 +47,7 @@ def anaemia_analysis (hbdict): return (anaemia, antype, iron, emergency) def get_anaemia_advice (input_tuple): + print ("in anaemia advice") output_phrase = "" (anaemia_bool, anaemia_type, iron_deficient, emerg) = input_tuple if anaemia_bool: @@ -62,6 +64,6 @@ def get_anaemia_advice (input_tuple): output_phrase = "you have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." return output_phrase -print (f"here is result: {get_anaemia_advice(anaemia_analysis (testdict))}") +#print (f"here is result: {get_anaemia_advice(anaemia_analysis (testdict))}") diff --git a/bmi.py b/bmi.py index 35a4f298d5e9..a79d48bc8fed 100644 --- a/bmi.py +++ b/bmi.py @@ -17,6 +17,7 @@ def bmi_advice(test_results): + print ("in bmi advice") weight = test_results["weight"]["test_value"] height = test_results["height"]["test_value"] bmi = weight / pow(height,2) @@ -35,4 +36,4 @@ def bmi_advice(test_results): output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string -print ("advice " + bmi_advice(test_results)) \ No newline at end of file +#print ("advice " + bmi_advice(test_results)) \ No newline at end of file diff --git a/diabetes.py b/diabetes.py index fb61cd82633e..0528a3235ab5 100644 --- a/diabetes.py +++ b/diabetes.py @@ -30,6 +30,7 @@ def get_dm_advice(inputattributes, inputdict): + print ("in dm advice") output_phrase = "" lifestyle = False #known dm @@ -69,4 +70,4 @@ def get_dm_advice(inputattributes, inputdict): output_phrase += "Quit smoking." return output_phrase -print(f"advice {get_dm_advice(test_attributes, testdict)}") \ No newline at end of file +#print(f"advice {get_dm_advice(test_attributes, testdict)}") \ No newline at end of file From c344e95fdb08ffdf63fb708063f362ccfed2c557 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:09:13 +0800 Subject: [PATCH 102/164] catch output phrase --- anaemia.py | 3 +++ bmi.py | 1 + diabetes.py | 2 +- lipids_ranges.py | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/anaemia.py b/anaemia.py index 8b9023c2ee58..756728950d37 100644 --- a/anaemia.py +++ b/anaemia.py @@ -24,6 +24,7 @@ #mcv need fl RBC need 10^6/uL #returns tuple - bool whether anaemia, and bool whether iron deficient def anaemia_analysis (hbdict): + output_phrase = "i didn't catch that" print ("in anaemia analysis") hblevel = hbdict["hb"]["test_value"] emergency = True if hblevel < 7 else False @@ -62,6 +63,8 @@ def get_anaemia_advice (input_tuple): output_phrase = "you have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." elif anaemia_type == "normocytic": output_phrase = "you have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." + else: + output_phrase = "you don't have anaemia." return output_phrase #print (f"here is result: {get_anaemia_advice(anaemia_analysis (testdict))}") diff --git a/bmi.py b/bmi.py index a79d48bc8fed..b8618c51426d 100644 --- a/bmi.py +++ b/bmi.py @@ -18,6 +18,7 @@ def bmi_advice(test_results): print ("in bmi advice") + output_string = "I didn't catch that" weight = test_results["weight"]["test_value"] height = test_results["height"]["test_value"] bmi = weight / pow(height,2) diff --git a/diabetes.py b/diabetes.py index 0528a3235ab5..66469b7678fe 100644 --- a/diabetes.py +++ b/diabetes.py @@ -31,7 +31,7 @@ def get_dm_advice(inputattributes, inputdict): print ("in dm advice") - output_phrase = "" + output_phrase = "i didn't catch that" lifestyle = False #known dm a1c_value = inputdict["hba1c"]["test_value"] diff --git a/lipids_ranges.py b/lipids_ranges.py index 991be250d668..2be5ec98535b 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -227,7 +227,7 @@ def getLDLBPtarget (attributes,testvals): curdict = agedict[20] agebracket = 0 if age <35 else 1 else: - print ("you are too young to use this calculator") + output_phrase = "you are too young to use this calculator" return 0 # age only points From e35682fa222e29fdbd1a00b2afee9ff17b5388a8 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:09:50 +0800 Subject: [PATCH 103/164] f --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 6acc79744786..1b76f7196a03 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -92,7 +92,7 @@ # Insert YT logic #test_results test_attributes for key, value in test_results.items(): - print ("looking at {key} and {value}") + print (f"looking at {key} and {value}") if value["test_found"]: if key == "mcv": print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") From aed77e0b7c67f6357c170c1708005c3e00742785 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:11:23 +0800 Subject: [PATCH 104/164] gender and race lower --- lipids_ranges.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 2be5ec98535b..6147d0398ba4 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -158,7 +158,7 @@ def getLDLBPtarget (attributes,testvals): #start scoring #print (f"scoring now") score = 0 - sex = 0 if attributes["sex"] == "male" else 1 + sex = 0 if attributes["sex"].lower() == "male" else 1 age = attributes["age"] tcval = testvals ["total_cholesterol"]["test_value"] if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": @@ -245,11 +245,11 @@ def getLDLBPtarget (attributes,testvals): #print (f"agescore {agescore} after smoking") score += agescore - if attributes["race"] == "indian": + if attributes["race"].lower() == "indian": raceint = 0 - elif attributes["race"] == "malay": + elif attributes["race"].lower() == "malay": raceint = 1 - elif attributes["race"] == "chinese": + elif attributes["race"].lower() == "chinese": raceint = 2 #matching to cardiovascular risk bracket From 9d5e8fb74331cd16185c637183a28b76f7a290ac Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:15:10 +0800 Subject: [PATCH 105/164] ldl bp --- bmi.py | 8 ++++---- streamlit_app.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bmi.py b/bmi.py index b8618c51426d..c7da421c6ab6 100644 --- a/bmi.py +++ b/bmi.py @@ -24,15 +24,15 @@ def bmi_advice(test_results): bmi = weight / pow(height,2) weightloss = False if bmi >=27.5: - output_string = "You are obese. " + output_string = "You are obese. BMI is " + bmi weightloss = True elif bmi >= 23: - output_string = "You are overweight. " + output_string = "You are overweight. BMI is " + bmi weightloss = True elif bmi < 18.5: - output_string = "You are underweight. Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." + output_string = "You are underweight. BMI is " + bmi+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." else: - output_string = "You have a healthy BMI." + output_string = "You have a healthy BMI. BMI is " + bmi if weightloss: output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string diff --git a/streamlit_app.py b/streamlit_app.py index 1b76f7196a03..9d66c992152e 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -101,8 +101,8 @@ st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") elif key == "glucose": - st.write (f"LDL/BP {get_dm_advice(test_attributes, test_results)}") - print (f"LDL/BP {get_dm_advice(test_attributes, test_results)}") + st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") + print (f"glucose {get_dm_advice(test_attributes, test_results)}") elif key == "systolic_bp": if not test_results["ldl_cholesterol"]["test_found"]: st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") From 216a8e019efb56994f0c42c7b07a944653c5ee53 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 21 Jan 2024 21:15:36 +0800 Subject: [PATCH 106/164] catch bp --- lipids_ranges.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lipids_ranges.py b/lipids_ranges.py index 6147d0398ba4..4f3f6d4665d0 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -288,6 +288,8 @@ def getLDLBPtarget (attributes,testvals): output_phrase += "\n Your blood pressure is high. Your target should be " + BP_target[0] + "/" + BP_target[1] + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." + else: + output_phrase += "your BP is in the normal range." if attributes["smoker"]: output_phrase += "\nQuit smoking." return output_phrase From ee5f2384f73e7cc0ea5cb8c5423c8099b1232aaa Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:17:56 +0800 Subject: [PATCH 107/164] Update bmi.py --- bmi.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bmi.py b/bmi.py index c7da421c6ab6..cefff14025fd 100644 --- a/bmi.py +++ b/bmi.py @@ -24,17 +24,17 @@ def bmi_advice(test_results): bmi = weight / pow(height,2) weightloss = False if bmi >=27.5: - output_string = "You are obese. BMI is " + bmi + output_string = "You are obese. BMI is " + str(bmi) weightloss = True elif bmi >= 23: - output_string = "You are overweight. BMI is " + bmi + output_string = "You are overweight. BMI is " + str(bmi) weightloss = True elif bmi < 18.5: - output_string = "You are underweight. BMI is " + bmi+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." + output_string = "You are underweight. BMI is " + str(bmi)+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." else: - output_string = "You have a healthy BMI. BMI is " + bmi + output_string = "You have a healthy BMI. BMI is " + str(bmi) if weightloss: output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string -#print ("advice " + bmi_advice(test_results)) \ No newline at end of file +#print ("advice " + bmi_advice(test_results)) From 1a70534db7883780d7c5349e2c28397ab6b1a995 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 14:49:39 +0800 Subject: [PATCH 108/164] Update lipids_ranges.py BP exception --- lipids_ranges.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lipids_ranges.py b/lipids_ranges.py index 6147d0398ba4..31ce5431ff2d 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -260,6 +260,7 @@ def getLDLBPtarget (attributes,testvals): "<5": ((8, 17), (10, 18), (12, 20)), } recmeds = True + BP_target = (140,90) if score >= cvriskdict[">20"][raceint][sex]: LDLtargetcalc = 1.8 BP_target = (130, 80) From b80669cca25c073977d1e93bdb2a339a6eac84f3 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 15:30:49 +0800 Subject: [PATCH 109/164] Update lipids_ranges.py --- lipids_ranges.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 31ce5431ff2d..53c60138ad30 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -65,12 +65,15 @@ "heart_attack" : False , "race" :"indian", "on_BP_meds" : False, + "sys_BP": 120 } def getLDLBPtarget (attributes,testvals): print ("in ldl target") LDLtargetcalc = 0 BP_target = (0, 0) + bval = testvals ["systolic_bp"]["test_value"] if testvals["systolic_bp"]["test_found"] else attributes["sys_bp"] + # check all attributes present else return "invalid" if(attributes["stroke"]): LDLtargetcalc = 1.8 BP_target = (140, 90) #with disclaimer @@ -82,13 +85,16 @@ def getLDLBPtarget (attributes,testvals): LDLtargetcalc = 2.6 if(attributes["heart_attack"]): LDLtargetcalc = 1.4 + BP_target = (130, 80) #SGFRS scoring, only if no stroke or diabetes then proceed if LDLtargetcalc == 0: #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 - agedict = { + if bval * attributes["age"] * attributes["sex"] * attributes["race"] == 0: + return "more information is needed to calculate your blood pressure or cholesterol target. In general, BP <140/90 and LDL <3.4 if no other risk factors." + agedict = { 20 : { "age": ( (-9, -7), #20-34 (M, F) @@ -192,7 +198,6 @@ def getLDLBPtarget (attributes,testvals): hdlbracket = -1 print ("invalid cholesterol units") - bval = testvals ["systolic_bp"]["test_value"] if bval > 159: bpbracket = 3 elif bval > 139: bpbracket = 2 elif bval > 129: bpbracket = 1 From bdd138aa4d189d61b146e418a5cfabe0901df816 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 19:38:27 +0800 Subject: [PATCH 110/164] minor edits to catch missing values --- lipids_ranges.py | 8 ++++---- streamlit_app.py | 7 +------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 5bcc54eb93ce..a7e47f30695c 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -85,15 +85,15 @@ def getLDLBPtarget (attributes,testvals): LDLtargetcalc = 2.6 if(attributes["heart_attack"]): LDLtargetcalc = 1.4 - BP_target = (130, 80) + BP_target = (130, 80) #SGFRS scoring, only if no stroke or diabetes then proceed if LDLtargetcalc == 0: #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 - if bval * attributes["age"] * attributes["sex"] * attributes["race"] == 0: - return "more information is needed to calculate your blood pressure or cholesterol target. In general, BP <140/90 and LDL <3.4 if no other risk factors." + if bval * attributes["age"] * attributes["sex"] * attributes["race"] * testvals["total_cholesterol"]["test_value"]* testvals ["hdl_cholesterol"]["test_value"]== 0: + return "more information is needed to calculate your blood pressure or cholesterol target. In general, BP <140/90 and LDL <3.4 if no other risk factors." agedict = { 20 : { "age": ( @@ -265,7 +265,7 @@ def getLDLBPtarget (attributes,testvals): "<5": ((8, 17), (10, 18), (12, 20)), } recmeds = True - BP_target = (140,90) + BP_target = (140,90) if score >= cvriskdict[">20"][raceint][sex]: LDLtargetcalc = 1.8 BP_target = (130, 80) diff --git a/streamlit_app.py b/streamlit_app.py index 9d66c992152e..483fd8148eb0 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -108,12 +108,7 @@ st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") elif key == "weight": st.write (f"BMI {bmi_advice(test_results)}") - - - - - - + with tab2: st.header('Lab measurements included for analysis') From e3bb050932d083bd75a8bdbc4fd08cec58dc937f Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 19:40:48 +0800 Subject: [PATCH 111/164] edit phrases --- lipids_ranges.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index a7e47f30695c..725e17598688 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -93,7 +93,7 @@ def getLDLBPtarget (attributes,testvals): # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 if bval * attributes["age"] * attributes["sex"] * attributes["race"] * testvals["total_cholesterol"]["test_value"]* testvals ["hdl_cholesterol"]["test_value"]== 0: - return "more information is needed to calculate your blood pressure or cholesterol target. In general, BP <140/90 and LDL <3.4 if no other risk factors." + return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." agedict = { 20 : { "age": ( @@ -232,8 +232,7 @@ def getLDLBPtarget (attributes,testvals): curdict = agedict[20] agebracket = 0 if age <35 else 1 else: - output_phrase = "you are too young to use this calculator" - return 0 + return "You are too young to use this calculator. In general, aim BP <140/90 and LDL < 3.4." # age only points agescore += curdict["age"][agebracket][sex] From dc7b848a9319cc00102ee9a0170ad92a8582225e Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 20:38:37 +0800 Subject: [PATCH 112/164] minor edits --- __pycache__/anaemia.cpython-311.pyc | Bin 0 -> 3070 bytes __pycache__/bmi.cpython-311.pyc | Bin 0 -> 2118 bytes __pycache__/chatgpt_values.cpython-311.pyc | Bin 0 -> 3762 bytes __pycache__/diabetes.cpython-311.pyc | Bin 0 -> 2659 bytes __pycache__/image_loading.cpython-311.pyc | Bin 0 -> 2032 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 0 -> 8825 bytes lipids_ranges.py | 2 +- 7 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 __pycache__/anaemia.cpython-311.pyc create mode 100644 __pycache__/bmi.cpython-311.pyc create mode 100644 __pycache__/chatgpt_values.cpython-311.pyc create mode 100644 __pycache__/diabetes.cpython-311.pyc create mode 100644 __pycache__/image_loading.cpython-311.pyc create mode 100644 __pycache__/lipids_ranges.cpython-311.pyc diff --git a/__pycache__/anaemia.cpython-311.pyc b/__pycache__/anaemia.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7468614e6f5b7ac22938f3e66b33f6cf0ebd2d4a GIT binary patch literal 3070 zcma)8-ESMm5x+ZkZT2+P|gdC+~Z zdwX<9ki{V|P@(Vx(U%ad3+Sm$Q55K(LJ5309ALmepY%q+FGZd@d;HP|`f<>$_GV^h zW@mmg!@uNmX$hViYk#LsMw0$1K4wpHx_R>eHs4A_A~I1(4Bq(5#HFtU&{d*EyyVN+ z7ZOQ5m%flm8dim5ekE;Y_fGGDrjJiQg>^F#ra5)_e$DZ0GTpbZ>CrG1(LLMXVK&+_ zTHCh_`|KC~`V`!iPP1ak3w^OLX6dak#j5(g4mx?LG^)A`tl6W%CI;`D=Rk$~$UT{# z;S=T0@b$MjMV7h}iM=&DEs^+Q-&48@NgPBx2KTmQqV-}RpIpeClaF&@dHQsf3z}1l zQxl!%J?SM#x(BiCY25_d@5V3KxpbPn8_8rATF?5@fxz{W-6Y8##DzmFM%12WD?&fX z^;CQ9l7%Y^P4hEXK~f?4o_a2Zg>Is&cC~J-7XPC}mi`nwe-nu5oDYa7KJF9^L=0m8 zh$9_yy@7ZGb0FFX+n8Dg7XQt*Yq;!+@HGL;sYvAB$4um&iG3)soS=&(Ok0M|9KFrq zpFl7W@Qe_qZHHMCW~a!g>zN!mwYd!x%IQrdOf;DR_=#5?$J|VXYNJXForgKc<4uq6 zHyaGQG}IbZleVZCrl>_(o!WXkaw*iNu7@hNdAmu&xWODd)GTWA4rOi%yh5|*`zJd; zuYBqPxzhBS&35Gzo9;5BMJv0G?ujFAWyc|gU9UW(*yN3eSU;$^oKb9<2ER?e##Ym$ zm8s2gvmNHA`~7+7-UEwo!|Q5*ZeI!txBP3bWObOlb}U~X$=8SS^&nH|zyIRiAUn$3 z^w)xw^}(-y|7HKn!@a}3BkI2uXt_iByw|UcwDHK90!1NNuqQ*!O#GkZC&}Xl>D1QI^oNh5^M2ebywXN)hoW;tmoxM}*c4-4NwaMtcn~tz%or=-6{9 zNVgI6axewe1E%acqUCxS0n!1~9_EH)mk_XP%(0*wP*lgjaG)SzS{Tp_5NBBDW%OC( zIk?7V&ez}=*ut($U00Nj@QHaQMNqlO1xcN{qTXkw%V@{3U4u}DI6e@*L^p7u5KSm* zs6Eg}P|b0Oikn6!0c2S*CD#DCwZPcQ5$}uQ+OK=~|ONhEnsvFpZpfk9; zAfk;br8N-nI2VeV4m;QceV_r%lp=!;t7F?m8wb!CX}g3>=m%`G+-d*ML@;VX@`$)N zbR-H*5RzmQLxk0xI}J_NgeXM~_WufGnJo(}Jp35`NK7m}b2}oQdlo_^edIWIOfPlk2u&Fx@#{@d$ik1KyZGZ(qP3Azz zEr_|uRTQc@?Q()GhtX+58%8}!=)}oIN~-@hMd z#eVlhyD`*m1nTl2exj}q)%CF=t$d~WkNijDxU}*_5xX;zz+V0;apAZig5>>wy{=3M#N*$)7(}gj1S01^s-UzFeekIwf+#4o(2DpE*gzkS6G8N;Zzp|`KKYs5^qSg2on*f=-}%n> z*XR44xv%p1oPqJ{d*8BGhYaH{%{(07qjA54>55?+wuw*wC9b7GlRLQ7wZwVDPJe2g zH|@+>qd0V`7AyaAyqNCg6q9OYm4|`7yjmKMY*e8;zENt*-cPu#=+~@126F zVxpIEm|JsHFVl!-%ZxolG!2@>cmD!*uNZ2F%r>us`)06XBK}Qt1MyD}4A`kh>&*mY z=|}uyvgAfWX+PUzBWY)@Ctw|4JX#}$v6-@mHq#p^dw5O9Wr#^TtD;qWW+U}@L@jJ@ zns#n89V|g>WS}+rKebBG%CAMn#gx74Sz7k)*kiEA9(&eVAe9#B4bvWP<#m)BCaSyV zOe^mOr0Tnb+Uu^xS`$mecI{xlA{JGaLzF|6$m-lRT4EUFp2ldqE!syo%O`A)^DWD1L;CS+`tly zN;jyHRnBejimtI)FoLj))USJBs!f7jeMb7!^O%5Ku#ZC)DB>{cDW^$%%(6t5Vtb6# z1y>AM#0Gbm@HtZR7!9HaZ(Lk&n97=_@T5sCQGdsbm|UWXM_%d1B3&R!Xof4JDf|lEq8%~<#3csM)irn z_jn_MhpbXX4zN)It=lf;XUn_NTBeT)9RX)YA<$OJu|KBS*l@ zYFeK5shf`y?7DvFYxf5a&(9s2pVwO<-a`T?*SsdWEsAVEQ2Hp83LQd)(guLUEPPv` zA9}z6JJR6-sE{f|GBPTxM$2D>C050=ZXS3ZzT$Vxq|*PE4h z1GXSgvC0BR*tl7;Qsy@7RTiTgwn(kDioOEW_gpo%eK#xcP^ve3Im|2ZlOrbKWCEZ3 z6QphYp2~KPZ>47Lre^M>X1aTe?bF@-^wk4*^Dln6d^dlved@n#ZtROgm)Eb-&yIb5 zY%53FQ`kJNf;QAC7Dlj&}0h$>~n6lj~+jFDEWdcc#0A z!?%++$~T8^4Q~}r?38!ZrG1@!-NGxkCvKd*S-4f$D!kPyzgWdXR{}>kc<@Wqzdk|=_I0X8*dssI20 literal 0 HcmV?d00001 diff --git a/__pycache__/chatgpt_values.cpython-311.pyc b/__pycache__/chatgpt_values.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d8172a87541249f89a4dcd8b5dbfccc5a140b709 GIT binary patch literal 3762 zcmd5<&2Jk;6d!+oC2<-zZ9`}n8ANdvyG?1+}P35CtJDOJ==0w%6U=S!QO_ zq;Vu4khpLFsS=vIBppK>G@oOJ2hn#vxF*qsA4qh!O zhC|?0!=Q>7Y8^`#pyYx9(xH}-M$Oc%eY1VNvOLs-0}U)U_OWA~V~O4eF^g#*r;kEL zWEaF)tXSIqDKb?3VEAzPjtw9m(m7lQ-vI|<#8L@1mF3x;L*0Un*$xd;tR^J%S&$9A zmeBg~3>+@ud1@^YCUA@B%@&*zicKQm9Qc0R8Y*u#OBko&F!j?th{3K5rdQLcyrCI2 zwM7kx9bweSmoaElJCj(JIh-9T`{^s6IlZm&b63urCN)kO`E7mRN7)bk9zA5QuLsL( z@GjqaZjcBnl;B{o}qyN2ofN|)5#~%=Y^jbQ7^}kt2Ijshy zN|GF)GAII{Cl^DKU^)WaQ#|TWVTnfjF8;I&2ONmaj6YC@z5ulBk1uukePc&^&e7*EW zQ8=tli*s|Q&v{Wvyu6J3U9Zu4o2bHz%j-(a+h;$fj?c&x;0lJ_a15+)4op$8fV2^= zH!a|dz#j(O;N2UG3#CHXivkTGUP7goAeQi=4kxS-@nR;`h~Z^{YS`4`1Sp>5mR`~% zoGVSjnaofj1CVr+c-ep_)@)#}HrP>HFgv5dz#u{g6J8v6EU-^6D&c!E;DZ{6jayV# z2?ztjOyf|o_;i6u6_s+;Z@tQ?Um}HMXoS?iBzvp)iD7Yug+5qIBd0l zO|B~H%_^{3qL_v*iUayxmBD~?)&}g-UKx5cP_dU`*PHO+KSR?+n^VWvr@ozDpLU~1 zHjkZfC(BSDl=^*lp_iTfVs#_?>TlWNui0X6EZ=(p-z&Pu=6;_%?wrhE0Dadi0Do$@!WjhWJePd8@fHfG-1n7Q;gcX=as zxqE%{==7bHuU7A@y3xa%xg+k;6Yk0LkB^>zoV&1*yU@Mf%jCYie(yy$Q*@)nCjc82 z4tc4e^In+4>9m2=D%=a(nisPi6Fd)Fwil+Hjl%*jURO9dcb3Tu;ziV@GhUp+KP5$H z^4fYS+yApfRmSAyXNP1XL-i1`SEQVW=4tXg99G957ug&PCQp->MUaf8}J zIX9?1G~oudhf-bt>7h*5e|l)N>pwd*>8}6u(3HEo_Rvf2?z$DPhH}wvcB>N}3zfFe I{>DfDFZ`Nt>Hq)$ literal 0 HcmV?d00001 diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bfddb8bc37b05a357b667763d42f6e5313698a48 GIT binary patch literal 2659 zcmai0OK%%T5+1&vlOZiq)`N`OjuV+{nTeFg#z7J&aS}+t%8?NV3m5{3)^w9>a2`xg z4=oZRpu-+?*n@7%EPU{3ZZFl;^Dhowr|kKhLNBM#m7c0Y0uBGJWDHOTteydMQw{ER;*iybH=aVF!pU$T>YK~@Fb)EQ6G zt(bJkBP7$0Tltry*;WuGNL7%+srKUs(Svv^8tjP?4dTxABi2ol?}x4T4r1iOR2Dx7 zlewO%D6swqm=~t=s|Qh{PJB9X&@WE?$H@HD)*NVDd_iMjrm;BH2$Q9L_#nb#V0U?9 z7ve6Rp$a7BsU!@Q`0DLmmRX3H2$K%eX>X1p!icpZkdB4kM52ks7hE<7m)Lkpk~vA_ zA#x4K(;Z2Yl9lbkw*i1h$+u)mfeCGh>smohsVI9q9y5ahYHXYTl%l zKql@=5KU^d>#l)>Jq3Yi2fJ9%moZPkR(q@eC;s!06B6=0h!Qn1$b zv5{qqmtw&`Lyvrp1*8c+9ENB@Vz7ZN9o!K{1-gM;N2YPRi#DeUI|ii4LD%ZcFeVxP z#+3nbWY?hP^&Y zylJji(dYY=>kMj((}rtcZgjyfgU>bWfy!EY_bmjBD`7%trcEdZNH@SIwHzk82Rss5M-UoivrRrle0ciaL#E2@+!~EI#ln-Jj%NRKvpXuKh_3|qLT16X0=@b z7Y1j060x5O7NE|AuiCBvVXfWd(20J^V0F0ux^O?G;J&I&u0D0z$5U2HrcEe208Pg8 zJGVaA{o0}2*=@V+c6awni+;vghwgr6>#podXZMy(Ah_L0oo&MXwF`F~#iqf;4Z4rb zwn2AiMcwZDDilPGn6*jk@D=F|9_KF9^r7-oGn(*T+gO zbtmL$uMXUi_WGj>C))L)cHJwLk5k7fFOMD;NBNaUS5ES)!~CjOx+IsM$d{)r3~rui zSBKhF57A@QE1^J!J~~#9)hAkM@Xd*ah8ps6<*}k%(Ifv=l)N4Zq`C6&^3LPjj%3Dh zC0iUsPBP2G%<`cBL+Iqv+VIkvSK2??_7+MrL@f{1^272Eb0?SI8D4(J zE4@8acvAW!%oDk>5{mT_Ua|-tmwE~CnCc~tR0)57lt5Bk0qNk<N_sYDNm;d8TT#JqsNph#6{7jUVA|QD!8y+h_4wK`nimG{;yr<21TEWW~y=>kq gE_vC4hhFpM7RJTQ9Owc$)W)Ti(BfG6Jqe=y4Rfq1?f?J) literal 0 HcmV?d00001 diff --git a/__pycache__/image_loading.cpython-311.pyc b/__pycache__/image_loading.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..116bbef388e335ecbe699762a9ce0ef12be2cf9f GIT binary patch literal 2032 zcmZWq&2Jk;6rcUDy|!yRP1b4C3bLjF$wY}Lf)v_{s!G)ssiY9MNZmNHw%%##cD-KB zuG2KEkr5ms6hSHlHQd}w0ktPih`+){mROCH6I^<;)LT!ynb=!9%+9>`=Ixs|``-J_ z>@TTQ0zv!z-{<&S8KHmJWYEOE@Nxr$$H+vcU?E-LT+}7bWj(@qRF85V(_@?~y25!} zk8_^T6PzdYByiC>QcdY8f%%lIbTy-AK$gEl`j{C3den>p9XEvn%Ew-?&sfR}Ge?$XNua1moooKprDc;95@Zg|aC;7oWoHS*U3sAAK|Dqt+nc z*ULb93gcO*X$T`;*>1e~f+?Bu^T<=sJPWk~@*xBhK^W1c&9`qlR?RTAhqXGc}yi7&c zqp3R;3zzELH6~P9!``}K)iI55uizrpe`%JODNS&F$uvB}Wf5!It1lPN7H_(kxJ9S# zI1h{0ZG4GT)^YJttz55S+jEPHHM3%`6|Z8$^6p+W%J++|N3c<~D&8F4FshD)iwBNb zj9@zNJfsOGm$;f7g{@LB++`q5w69Kf)tUC}a$7BQ)IwJ+G(QVsYCEO{*|+}A&i<91 z?PTY=*}1L6zLMBhc22aG|Cnhj7dpy?u5tl{AT!lgrg|}?sF5PC&lXoYbPY#4|5K|gdR zBwsRxsnDb$nPNls*q;67#Rd|rmPS{P&Mu+VHyaUO@*}VPnbMFvyie4Z{irE#g7Zy) zOGDnC_Toc3$)mm-v61r_8Xk&U@si;yP zO!+8Ox>AL**UE%Oh+(gRY+;)hl1dfZ%O?nfIE{lvsaiAP5T}{wdIs@Id~x*P%+oYr zgBWG64-;5!ZcxbsAgQBoN@WWhHa)`pU>iWiK0#qKCb{hT26*+`0m_c_J#YY$S+HQq zcAo%&gO{D!z4d5iccr-$q$Yn{{eE@t!%iyKP34-GgVe;%#qC=lWREqM_A}~Fg}q5; z+sWj*nOqNvkr__5q#&*C6t?g0<+km;FS_Yz&?u98r&`j_`HpgGE4`K8Klx7U>(0rA z?#Ttf@BYNG-H#ug+dbF3wx1c_Ip3P^OuX00obF~$H?IcC>DKXfGT)Z-9OwB78V|1* z!a}4`$FNPqrJ`ffh+VJ3?IPL^6>BbegTKFRxOm|MD&KSAvXsi}?~^Ro*WjmNR0unU zH16>K1|*Nb&kpfBiC2#&={LkT=Q(_(oQL|=E&K`j2rL;0+&_WzBtZ}YG}#{X08O+9 zJwW5_K@U*8$)5lvoBRn-s>z=rO`^%4A>*kw8tDO=Zjbh!91%|RP)O2}Fx5jLNhF1L Kd+7g!$Mzpa4DPc4 literal 0 HcmV?d00001 diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..197814e4315ac6ffd0822cc8f33fb354531f4f13 GIT binary patch literal 8825 zcmcgxTWlLwdgfJ>G#p73FQP2V9@&v?$r5$5EL+ja_q!e2ac*{$DiqI%WJHnl%uu!% z67?1>K)69cq(PV1x~LwCt%5BIJ@g?@MbN(Fp#?}`022fP7~O}0Z){Vvsj)@+{f87q z$@V7MEy`H`ob%t#Isf&{o{Hh3aByzfb#YTi_8Z?u?W_Xl~|R)Xfe&dlSfcjRV@|?2j&;z zB|8iI>$CC^s4ZER{Smp;6pn%vEkC4{T1#esP%fEO`C+L^U5+iu3Z9yRL8%#R3o?#S zG6$Ae$sUsZiZ<`pG=E^JWKsM9xzrkq&Y!(CzbrEqVyh}90Tc9Y{hBc_x|60JyzOw(VDhtQCrHuY}@m+1@q?Zxnf~0 z(BBIE1}1Fd)n?4?+jFIhiMx3eVHb~?bVW_9Eo}m&y+PW-IX>`BpX z9NTXyj+8kxnE7)T3<0S&m9BnVqVtG_B=7O9=4bD^3guF zpGkbw#}2TAeDoUYXNUOc@Dpp=%8sxBHu%JpMq;JO#tnO3t9!5RE)0HwzhBl7>}b^r z*o7%-WJ77PcY`I;E%50p&X{i9MH}8e?GIYpS6lmVs+El_S!h#=nT@7}XcCyQI%XW0 z`@l@pF+;$FfH_vjn1GpQlYn!-}sm6pLR8Z6;ISLw5vnFoUCJLSG~YY*D-<5w0#%tx3zR{%FbpQb|*$%!2G0+8A^*$0hrl3W*it3d?Nmi zJJ_=7K4?Ex*KUILL%^J_V`vAo%b_}kcHp8NM9GHY_t?U&ok$F=3^)l*lG)SVzj1YGN0*<2xm8kCURoz;o~7HV*kTgnTlk+f!|I zExlaJrERWMTf?}aPNf`HCVJt-@@vaLVu0PX4$ z&-{9}cLH~<#&2TR)8^YhEzw&(OAt=4b|}l8+W9Hx~IChMs!`+$&6B|!E z***3?n`0la-+N+7yV!i%%{#d*SC6}oOzZ^a97r3;hbKmQZ`etl}d zRQ?3>@;zen5+Iua`v-)*1yEzPoL2VGton}dpQjWTW{R6Y4*~QAgJK6rZrq3|vJ{Rk z#*}5h7LG-wuqs7mnaNDjVp6~#2_zzZO_o+;2}N3n#9~Z}E3&F4AQn@khIftH(R|Xa zi0oHoX)zp$K(nNUWN9JxP*x@XLTp9$Nmrs$P>#xqKQbhpy(P_z9UC1vIV$<1OuByl zx->K4J0^t}rD#lwK~|BJu(~8I`U6@_QGElZ0aN(DzWeUG@P7l~?7zmN{693dU`EDM z=&c1~8y;nPmB6@##sVKJLo_B6449NbJd~p}HghADtQs9j@l?qY9-o`a+%KbqvM6}X zB!yHO%1wN%jN`#I)fATLr4-&BBm4m80floB*jkp>9-vLrbzhkTfDEltI{<%Fl^i4N zaR55LGC?x}81uuBD+estD3t=`BmgwggKGsBDX*#~CCW4a*EEGenL-ad!!+)oF*H?! zlB@U$P+X!4P7sH+%p;1p%XFmj41tS8vXtSA?;7N3Z91kxilCV*<;FB|jX?43RlTO1 zBla4K42bdh>Vuo6YQT~i@3kc>ULDWgQXC*xwUSek*5%*`i-f(f1wV4RLUg_akAgLt zo+UtbuVu{M)3s#rZVghzkfmR|?G%$-bzsJ)thd#d)@|IMlL zUlPL~6Zk2C2LQ?i0(%LNxspybKpE&?#QQq3VFc%rlrx}|uMtl_03zhiXnc^sX@D}( zl~Xk04kXVhvos}^6o%J75(Amm!_kHeDo#ZQ@lC+LTCxQ~;i#<217>)U#{iWjY?ypf?yioVG^V=4xoF3Hvv4doAXoY> zCj&*fSf(W~rr1{Aua0?ix@l|%g{SS^DurjmJh6U22+MQx?D*(&>)7Zp9+t`BvC-$I znaQ^lKd~$j2msWaB%D?lW)~F!F!A?@2wv!@4mFlGm@O0zhJ4Zmzb5%5eA0+$p;c)C zMu-MbDp^?8q+!@N3}fF|l`hv9Zc*)2r6W`eiR72=C-5}{u8uA8!Wiep^+8w*Ne}3= zO;GWNqv}wdjZ=bDbyXDL0CYhxuEaDMl@)5$(2#_38xN1I|x|moUCX#GdH0s zMZ!z6v?OaWbck@EYS;Q+;FaNXIPQuZf#4a$E83Q%$U(FyMOuzA^b}1V#wO*c8rD{& zcxY7(BiX)E;ph@Jq)5zP-SeVMAK~Cba@2U0LEXW@>AvJ8O8#X? zDf0b97%poJ<4Ej*4AntI3xi$g1W*|OOhmM5i)S(Fvpy*~1VsvO$c-A12;@tcu6mJ? z;P{~IQ`(U}<-Y?^DBF|Qq*jT`@47KSoRNSMOQ@06T28$ahO^*`>eAe1epSUCV_A-B zzSiXAD|JAd9tGVqp9 zxMh~(WGCcJJq}+8E977d<+T499lB!=#5j2PuMA+&} z?pf8dsobq}H=`gyoCOm2P`eyff$#^=MHn3gB)V{Et8v`V7Hisl(jA1k&H-t$~&L@-{^d@bB1SETP2{+I&2u;PzWGEyPvoh0-g2&)+#W zJ@>XME9zW45s$CV-HgiTmGFu@cRm(KP~@v~=VIj2xoR`HjFZg4VX}WY64r+0hyG=h zt2tg%)Ol`v)fZnawV{Z^lxJ^Mt*1P~CNAMmb>TYm$ndqLC3C7^>Cr7cc}q{x<$iRd z*x`9}r8xPMFP8Pm>tD_3llSt1mN}9AKo<_KUDt)NJpO(7QGQ9)Khz$be`a%JkLb3Z zios;vSM>H|#GSP3rao6@$4&T1#&9>xWP9 zadGed%#F;AXY?QyKHb*0OY<|ED`(uabr)>il~#kjBRiOTTkkwr!0tZUaO;Pr3c}PE zgI~U*PhT$x*S~t0e{V^@8OblN>Nk@GA&Ki>+IYc)$0gHyrvISXU7Fo9Emmhi)4v%E z_8{Rt!ngN-$7G2n1Wg9lMKi_(n@rw)l_txceb_}$U&Yzl*;X+S@S41PLFnlPVShge z4k7?-5%z9LG!RHt&krZOZ#>~_tr!3@w#tgp;66|>S-aXQ*5+=Y0WxC6V{mk4tVL&U zPS%~TJ#`LlItL5RA>BE&(X{D2o_8M4_%r@5&ScERHgC?Yx9!KM!<*kTtatdIMY$UA)n`-pBI$=gSswRh#a2le)&>(}-6lNk#??IB$_ye{a%v8TfHrZ8O) zW^`fZiwB#+#k_E_*zU|OJYLPLuHDZK<_3!nch2-_ceZ=ok-M6^x_i1`$`1YpoewvK zOL^fE=?pwhW|Hg1+;nc5l$bx=lidS@-pk#isqs^9)?1^J&g|f`?w-um-KP=Svj-nf zXQtQ2va8wEqUgw;dwef*Z|!!jJJh8&c zeKK(t0f@w|I75u8Ol3Duu+R6dntF}vp3eJ zb(e2l)m;;X=7~&mrP*Nb%5`oEJ$a$0Xm{moYc}0`WW7iCPHqHr?{vXFow-b0o@_`L z_E!wXmXRu7v+f;OKd5^VxIVC8iMFh_(A-Vw>CP_dLhn=I;HH2Q*slxy>)uUXql=!d z%q7@T?8-Ii;{K;%|EAbq5D)9(;q|FaaXc@M|0b4`o8qy&c#N}PSFZ7*d!pzXD|U`l zTC5%v8GuY{#cptRAqrf3QSyb3?A2UCclECYw~oFkOyq?LUe$}_0{b;RA z_YABb);;4J6S@bxnaYb(wc1~0@aUc+>);yOIH-G$Z;HqB;_)2}F5Poz?SbwY*)Z## zW3|olw&Cf?T!N9BJMxYLx{Z34ZEWMlrtM7Lb_Nx^`>uc|Y zzJ*ZtB_oKo_N=Je_T^H#Z3v~?daBsw$)@$T{ojNf|N=~hPn%f5C^%^w;9o^(a$70}0v$h!)J0MNbtz|Ep_51eFCjUI z1n~N6cC>MTN6nS@j0Um2C^%4h(OO80-BEP!LAn*4-eQ}h;uf4>26)t7*&~~c-4(;j IAvePR0-;g|0ssI2 literal 0 HcmV?d00001 diff --git a/lipids_ranges.py b/lipids_ranges.py index 725e17598688..50c356ea68e1 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -94,7 +94,7 @@ def getLDLBPtarget (attributes,testvals): # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 if bval * attributes["age"] * attributes["sex"] * attributes["race"] * testvals["total_cholesterol"]["test_value"]* testvals ["hdl_cholesterol"]["test_value"]== 0: return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." - agedict = { + agedict = { 20 : { "age": ( (-9, -7), #20-34 (M, F) From cce43f3157c006954628706b978e95184050bd44 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 21:19:25 +0800 Subject: [PATCH 113/164] comment dotenv for APIkey and print outputs --- .gitignore | 1 + __pycache__/image_loading.cpython-311.pyc | Bin 2032 -> 2044 bytes image_loading.py | 4 +- streamlit_app.py | 6 ++- testing.py | 45 ++++++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 testing.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..2eea525d885d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/__pycache__/image_loading.cpython-311.pyc b/__pycache__/image_loading.cpython-311.pyc index 116bbef388e335ecbe699762a9ce0ef12be2cf9f..0afdeeacd54466ffd86352f6c111a14b58e1eabf 100644 GIT binary patch delta 256 zcmeys|A(J}Tkb$9wZ5bm2!)hRgfE1Q0Aft+xfuWYAN2i2)@^ThuM&8M~8BkvAoHXlX?hUpBG&$6ga{=lp)RKuLYC<#&l2DQv7 zOp|3q}K z!vvHlVh0j0ffh3qi2w;rwp%PEnYpRAnDdj1Zm||6=A{GKIjMP*Ls;i?X#-V&>?&S3 z`7f&?*9~6b364FH4Q@9k%d<(cseE8yVpW-J$0p7>LwN!7OwEfN%9B&rHp+mstz;+? a0#Zc+K;jpNO>TZlX-=wLk;P;~_R|2GCq8fh diff --git a/image_loading.py b/image_loading.py index 675fdeabb9be..6d11b2694541 100644 --- a/image_loading.py +++ b/image_loading.py @@ -25,11 +25,11 @@ def remove_nric(text): def extract_text(image,ocr_model): ocr_start_time = time.time() result = ocr_model.ocr(image) - result = result[0] #idk why this needs a result[0] instead of result for Github + #result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] - extracted_text += txt + " " + extracted_text += str(txt) + " " extracted_text_clean = remove_nric(extracted_text) ocr_end_time = time.time() ocr_time = int(ocr_end_time - ocr_start_time) diff --git a/streamlit_app.py b/streamlit_app.py index 483fd8148eb0..ab37fc26525f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -14,8 +14,10 @@ from diabetes import get_dm_advice from anaemia import anaemia_analysis, get_anaemia_advice from bmi import bmi_advice +#from dotenv import load_dotenv -API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret +#load_dotenv() +API_KEY = os.environ['API_KEY'] # API_KEY in secret client = OpenAI(api_key=API_KEY) @@ -90,6 +92,8 @@ st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") st.text("") # Insert YT logic + print (test_results) + print (test_attributes) #test_results test_attributes for key, value in test_results.items(): print (f"looking at {key} and {value}") diff --git a/testing.py b/testing.py new file mode 100644 index 000000000000..cfcd05b43a18 --- /dev/null +++ b/testing.py @@ -0,0 +1,45 @@ +test_attributes = { +"age":57 +"sex":"Female" +"race":"Chinese" +"smoker":false +"stroke":false +"diabetes":false +"heart_attack":false +"ckd":false +"on_BP_meds":false +"systolic_blood_pressure":NULL +} + +test_results = { + 'ldl_cholesterol': {'test_found': True, 'test_value': 2.2, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'hdl_cholesterol': {'test_found': True, 'test_value': 1, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'total_cholesterol': {'test_found': True, 'test_value': 3.7, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'mcv': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, + 'hb': {'test_found': True, 'test_value': 15.6, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, + 'rbc_count': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, + 'glucose': {'test_found': True, 'test_value': 5.3, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, + 'hba1c': {'test_found': True, 'test_value': 5.8, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, + 'systolic_bp': {'test_found': True, 'test_value': 141, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, + 'diastolic_bp': {'test_found': True, 'test_value': 73, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, + 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, + 'weight': {'test_found': True, 'test_value': 58, 'test_unit': 'kg', 'test_ref_min': False, 'test_ref_max': False} + } + +for key, value in test_results.items(): + print (f"looking at {key} and {value}") + if value["test_found"]: + if key == "mcv": + print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") + st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") + elif key == "ldl_cholesterol": + st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") + print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") + elif key == "glucose": + st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") + print (f"glucose {get_dm_advice(test_attributes, test_results)}") + elif key == "systolic_bp": + if not test_results["ldl_cholesterol"]["test_found"]: + st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") + elif key == "weight": + st.write (f"BMI {bmi_advice(test_results)}") \ No newline at end of file From 0621b49b6f0ecb233618b41f213c6a6fdf612580 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 21:19:38 +0800 Subject: [PATCH 114/164] spacing --- testing.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/testing.py b/testing.py index cfcd05b43a18..71bf2cacd2b9 100644 --- a/testing.py +++ b/testing.py @@ -1,14 +1,14 @@ test_attributes = { -"age":57 -"sex":"Female" -"race":"Chinese" -"smoker":false -"stroke":false -"diabetes":false -"heart_attack":false -"ckd":false -"on_BP_meds":false -"systolic_blood_pressure":NULL + "age":57 + "sex":"Female" + "race":"Chinese" + "smoker":false + "stroke":false + "diabetes":false + "heart_attack":false + "ckd":false + "on_BP_meds":false + "systolic_blood_pressure":NULL } test_results = { @@ -24,7 +24,7 @@ 'diastolic_bp': {'test_found': True, 'test_value': 73, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, 'weight': {'test_found': True, 'test_value': 58, 'test_unit': 'kg', 'test_ref_min': False, 'test_ref_max': False} - } +} for key, value in test_results.items(): print (f"looking at {key} and {value}") From f7f1b46e1113aa5d432104472df4681657d3500b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 21:29:11 +0800 Subject: [PATCH 115/164] edit return condition --- lipids_ranges.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 50c356ea68e1..8154b4912900 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -88,13 +88,14 @@ def getLDLBPtarget (attributes,testvals): BP_target = (130, 80) #SGFRS scoring, only if no stroke or diabetes then proceed if LDLtargetcalc == 0: + #function "all" returns true if no values are false (0 values map to false) i.e. if any of these are 0 or empty, return + if all (bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]): + return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 - if bval * attributes["age"] * attributes["sex"] * attributes["race"] * testvals["total_cholesterol"]["test_value"]* testvals ["hdl_cholesterol"]["test_value"]== 0: - return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." - agedict = { + agedict = { 20 : { "age": ( (-9, -7), #20-34 (M, F) From 850c7e37fd00e261c7ffff3cb6a07ff9406aebf5 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 21:30:01 +0800 Subject: [PATCH 116/164] added testing --- testing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing.py b/testing.py index 71bf2cacd2b9..7121430e670a 100644 --- a/testing.py +++ b/testing.py @@ -1,3 +1,8 @@ +from lipids_ranges import getLDLBPtarget +from diabetes import get_dm_advice +from anaemia import anaemia_analysis, get_anaemia_advice +from bmi import bmi_advice + test_attributes = { "age":57 "sex":"Female" From 67aa29009285a9988613c6acac5f314324695f7b Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Mon, 22 Jan 2024 21:39:06 +0800 Subject: [PATCH 117/164] updated testing code --- __pycache__/lipids_ranges.cpython-311.pyc | Bin 8825 -> 8818 bytes lipids_ranges.py | 4 ++-- testing.py | 28 ++++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index 197814e4315ac6ffd0822cc8f33fb354531f4f13..a829b7b0d83c01fdc83c9e09ffb365249b375166 100644 GIT binary patch delta 425 zcmezA^2vpFIWI340}zzvuS=bwJRuaG zFcOb3MPzazw)j0_B`ftZ0|awKy+BhzF>Hs#58m?NO92$mu+OMCJ+ zmK9L3L#%O(Oq&(iyqTc_6FB9dtVIB;rTmK7zkr$$JuLR~@$gjQ< zSo48_p`Ov52}pS|MKOH=@uESz7^VyeFB8NQ%wqb;z`&CY5(1JR7#KO-m_INvhyY0j zFv-UxA@_leMM~}i7lX9o<{GKDY%(A>tz;-_0#Zc{K;jpNO>TZlX-=wLQQPEJ#mkCm N%#4yB7_gIIZ2-HlYs3Hm delta 413 zcmez5^3#QPIWI340}x0ju1n?L$a|WRkz?~sMh-@c8kQP{6hTRl92iuwGB5x|gfK*e zQAH;IWtL*9Vx4TrEW-iPlfsnEG&zzvo{@2~BAfE$JIoPKRs>5Cn58}W8_No)*df+9 zM#jyGY~IXJfeD;)P}U_7Yx76W&Ac2;w^$2`GV@9{ZxpX!!!Sn^hiv;nan9?A;bf%9C3_R%|u`Hl}J^?w|AP$IRVi0j-2C_jU z8`I`Ysh?~zAUCaKC~5>!MfE`97l%!5eoARhs$Eg*7.3 : M 11 F 13 - agedict = { + agedict = { 20 : { "age": ( (-9, -7), #20-34 (M, F) diff --git a/testing.py b/testing.py index 7121430e670a..159e93715a04 100644 --- a/testing.py +++ b/testing.py @@ -1,19 +1,20 @@ + from lipids_ranges import getLDLBPtarget from diabetes import get_dm_advice from anaemia import anaemia_analysis, get_anaemia_advice from bmi import bmi_advice test_attributes = { - "age":57 - "sex":"Female" - "race":"Chinese" - "smoker":false - "stroke":false - "diabetes":false - "heart_attack":false - "ckd":false - "on_BP_meds":false - "systolic_blood_pressure":NULL + "age":57, + "sex":"Female", + "race":"Chinese", + "smoker":False, + "stroke":False, + "diabetes":False, + "heart_attack":False, + "ckd":False, + "on_BP_meds":False, + "systolic_blood_pressure": None } test_results = { @@ -36,15 +37,12 @@ if value["test_found"]: if key == "mcv": print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") - st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") elif key == "ldl_cholesterol": - st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") elif key == "glucose": - st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") print (f"glucose {get_dm_advice(test_attributes, test_results)}") elif key == "systolic_bp": if not test_results["ldl_cholesterol"]["test_found"]: - st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") + print("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") elif key == "weight": - st.write (f"BMI {bmi_advice(test_results)}") \ No newline at end of file + print (f"BMI {bmi_advice(test_results)}") \ No newline at end of file From 46b0c757de087b3bba7a84833cfa1c9431428731 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Wed, 24 Jan 2024 20:58:29 +0800 Subject: [PATCH 118/164] remove mgdl --- __pycache__/lipids_ranges.cpython-311.pyc | Bin 8818 -> 9707 bytes lipids_ranges.py | 36 ++++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index a829b7b0d83c01fdc83c9e09ffb365249b375166..de794eedb523822059e44d042a20b8876f25e57a 100644 GIT binary patch delta 2490 zcmai#TTB#J7=UNa>~h%)uorfVxLjP73apocVyTEI0u^DQ2)cqUmVcFHcW2p)H=OAv zZ6ErmIc?G=HqjT0sWvvIiH|0IG40Ec4lg7=G(P%JwDqA)n)E-j%j|`won-!V{_p&^ zbD1-*`(F-MePgwnIDBpS2!0upC>XLwt0>e@}S|fOE zo6^u$!8=<_@0H=?@XbCv2kr?D-hw*V0`<2A*a{wK(0Yx~1kGA+8+c*6*4qI)p+)Px zecLD-VHdPQ8@(&Ic>`@O^H#S<2#cE}KtvvV^rg^a-JP%cj%JnFle21(Ot3d%&^!d# zC!573B=6{?14#l&r%rrG=8^2z2|*Hs11M)C9-R4HP?R@2+pMI%GIyq{poW8bG*-hN zjQ_4qSPeUobnArG;6d`9PFM|2tp*#Dg~tUB6|X+eVU@LY9E}-wY+jk*#>#jk3-lDk zw~9_AhjrqUt)dx8uTDCU5L`oRHvYzZi&uf|kv{VV^gp8e6ZGGSq)#U-2dl%U6PClt za)@l6*8iEO0gmdP`{XK&Wq@N5!$5AkI}kY$_3K7HBxWSXbwZF3OjRXW;Xsbsq;jbY z254n@W6NNEyYa~R@W>IlTB_1*J(}$h^_TbY@6%i5p3I3{lzPbsC-UC1O{#?9h_-4Q zhgY^EJDIa5Fd_@$MI@s+;=l-_B@z6k5yTPn7|VMQ7^4>|JQ<&C7dvriWB*vN-jZM+ zYzkJ79uxUsFj3-hYLf?n$q7!Xk!*#Rkz}VoS2R{{ET~%>pQ3+Ov^h@aBPMMcKTUr# zx#&n`WA+Q@&(K?y9_+uWY;z0XlO1A{#6iK$l>NrNXZ4$)Lw3M4%)mJ~55e08*$K09 zEtq71CQN(iMNx11^?5C~s&kSX zNS;D8%TpHQ1=bMD*_UBXF_*Io`|-4Kzv7L zTr(~v!(w_(xDbu538{2)&G2D7{`ismI&c02iyXu^b*++i*8P~Nw%L^x}Sv9j{c_$%J`HzkU6ac<`h^^0}&;58NILa zCzzwiYk5wRGg&RbB2SY!)`Z9v2B*nYrd=cbf~Fl8Q1cB4n0(hDLnyKD)TDKY5tL|y z63h8w`_1&N*39RvU&Ed5<&f&_Txr;^Hthc){p9R3quMjN(&bmX{Hx=W%G9iK;gUKv zzcL8v)xrXS_cF^x5EI4+ni9B`e`QY0BR2IPpa z-p+A-!U(Gk$S5l}Nc>D=4Qkdgt?V(a?6JpzE#b1j>P%3X4J!)~bvC*(6H{kmE6p)w zF}2d1TD@`|S(@WyfTg*?53+);@Dpy(a_=KXY`}yUz+CyzHXiScd5Dk19c7)R{#J2 delta 1776 zcmZvcO>7%Q6vubRAF+46P8~Z=Q^!r6q)C&yBuyI%qzN@GHK7FKhPE^@4J|LJT_>Bw zNe`qm3gOTriZmyr9LkCI!iRDJ2?+@aF6)B@`qiBqZL9*SnUDrF}c|+xLI} zeX}$E{mS!8!7mI$Q}B0x<;#Vg;ctS!sJb7gF1-HyQRBa<|Efp$GeUDE0?`=-I^ZyL z!jWAU#Gnh}aB;g}pHpa**8s1J@qzZ?zhdYA`Jz#t6m66OWMTBrhTox)ZA9udCn z?QK0-Bw~s_#8e^4Kle-+ry8?nUa+zTs0PDDw^X=bgz4rclG8RBMY4wEj7^eA@<`6w zgdmxRF@D<{ZgwiXSm$)k)(EFztn!jggi}9~mu(`P;z(YxiExU*7{-u@8>(zv1{mi? z%XqW@e67GfW-Hq)kSV5L^?3s?hGNAT+J!jarXKQU9u~C#dg7 za=|9TL%c`QCc+~kJY+{kLq}O(crIn>L3X{nO zMYc&1L&a6c1g8o|t;M;f zA6Df#Rd4XL9a4TcJ$SAJ$TbT*P|>9voHracpq-*F~SvzRV zgu)fH}SV`+!d{SYYkA!x#B8ceIBR zYYjBG%c8WsZyJiiqS$bOMY%y@o=;KW76La8?(vk7+DbZaOtBAVW)+;G9Y7ok z#VTJ9Ag{}YB`e>H#>fc&+<O`Q;V3zqBw}ddUCo`!%uXQacZn I|Bq7k9|DJd1^@s6 diff --git a/lipids_ranges.py b/lipids_ranges.py index 50b50e061eea..f9833ffb242e 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -89,7 +89,9 @@ def getLDLBPtarget (attributes,testvals): #SGFRS scoring, only if no stroke or diabetes then proceed if LDLtargetcalc == 0: #function "all" returns true if no values are false (0 values map to false) i.e. if any of these are 0 or empty, return - if all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): + if not all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): + print ("something missing "+str((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]))) + print(bool(bval), bool(attributes["age"]), bool (attributes["sex"]), bool(attributes["race"]), bool(testvals["total_cholesterol"]["test_value"]), bool(testvals ["hdl_cholesterol"]["test_value"])) return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score @@ -168,13 +170,13 @@ def getLDLBPtarget (attributes,testvals): sex = 0 if attributes["sex"].lower() == "male" else 1 age = attributes["age"] tcval = testvals ["total_cholesterol"]["test_value"] - if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": - if tcval > 280: cholbracket = 3 - elif tcval > 240: cholbracket = 2 - elif tcval > 200: cholbracket = 1 - elif tcval > 160: cholbracket = 0 - else: cholbracket = -1 - elif testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": + # if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + # if tcval > 280: cholbracket = 3 + # elif tcval > 240: cholbracket = 2 + # elif tcval > 200: cholbracket = 1 + # elif tcval > 160: cholbracket = 0 + # else: cholbracket = -1 + if testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": if tcval > 7.2: cholbracket = 3 elif tcval > 6.1: cholbracket = 2 elif tcval > 5.1: cholbracket = 1 @@ -182,14 +184,14 @@ def getLDLBPtarget (attributes,testvals): else: cholbracket = -1 else: cholbracket = -1 - print ("invalid cholesterol units") + return "invalid cholesterol units" - hval = testvals ["hdl_cholesterol"]["test_value"] - if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": - if hval > 59: hdlbracket = 0 - elif hval > 49: hdlbracket = 1 - elif hval > 40: hdlbracket = 2 - else: hdlbracket = 3 + # hval = testvals ["hdl_cholesterol"]["test_value"] + # if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + # if hval > 59: hdlbracket = 0 + # elif hval > 49: hdlbracket = 1 + # elif hval > 40: hdlbracket = 2 + # else: hdlbracket = 3 if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": if hval > 1.5: hdlbracket = 0 elif hval > 1.2: hdlbracket = 1 @@ -197,7 +199,7 @@ def getLDLBPtarget (attributes,testvals): else: hdlbracket = 3 else: hdlbracket = -1 - print ("invalid cholesterol units") + return "invalid cholesterol units" if bval > 159: bpbracket = 3 elif bval > 139: bpbracket = 2 @@ -291,7 +293,7 @@ def getLDLBPtarget (attributes,testvals): if bp[0] > 180 or bp[1] > 120: output_phrase += " \n Your blood pressure is dangerously high. Visit a doctor for assessment.\n" else: - output_phrase += "\n Your blood pressure is high. Your target should be " + BP_target[0] + "/" + BP_target[1] + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." + output_phrase += "\n Your blood pressure is high. Your target should be " + str(BP_target[0]) + "/" + str(BP_target[1]) + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: From 3a14422720c86132cc747e83f5a451e1cdae6c42 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Wed, 24 Jan 2024 21:22:11 +0800 Subject: [PATCH 119/164] rephrase advice --- __pycache__/anaemia.cpython-311.pyc | Bin 3070 -> 2523 bytes __pycache__/bmi.cpython-311.pyc | Bin 2118 -> 2294 bytes __pycache__/diabetes.cpython-311.pyc | Bin 2659 -> 2949 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 9707 -> 9376 bytes anaemia.py | 50 +++++++--------------- bmi.py | 13 +++--- diabetes.py | 22 ++++++---- lipids_ranges.py | 8 ++-- streamlit_app.py | 6 +-- testing.py | 12 +++--- 10 files changed, 49 insertions(+), 62 deletions(-) diff --git a/__pycache__/anaemia.cpython-311.pyc b/__pycache__/anaemia.cpython-311.pyc index 7468614e6f5b7ac22938f3e66b33f6cf0ebd2d4a..481fd3d4a114ecc7f463f0f97e22d61d5be5b572 100644 GIT binary patch delta 789 zcmZWm&ubGw6rR~1&2BcEYSXl}KX9Ohk~9{)c(JV~1t}>lk=h@;FoS0Lq>bV&gU8Z`PXz&G2+}Elaj_qinJy)^459t(+OB}y2 zXRz;mroSYWI=(DX!9)A73gzyJmA%B>;83{{e9~7BBH`dz2%!hJCF~t;vI^REo)Y9x zhm>6>gYp%D#5UmsxgMfSAVOK?(Kd2vk@2!4Tt<;#2ophg*`*{Dqk>cM$UItiJy#$H zVO9`~Be#fl&*o3kT~uJSKsfafE24afF^o#g^X9+V$5#g|1scb5#wrYa^EuoM{+MHC zM}NXyDpGndqoPFb@tsJSP_ak2r^^L`ef6<5Cds%A?-vNZtFsR^>&SVr>@T;?ji$NL zmT9qmuU2}s)QYE1v~*KTx6Q%2UYn{{Tjop`Ky^)dbLZX7R_4~nSSyqLSLrIiT2s0p z#I_MXs?_Xysbx(2(*e=0AINrcYrxO?*{%kXt4he)k?7HS{dVnvw6fDDk#sYXmb&3B z-Cy(Orv=U;0Z$tFym%6Eg6l+rN-@dS1Yf`{w81w8y?J}Tj-u~25XQX)%y WQl?Ob_bez`?)XR-jKK5IyZ9HjqQW2m delta 1426 zcmZWo&rcgi6rR~%v))~U!8Q(wqd1`g*@3F9Dp0GEN3EHV zwOg+$4z#K&6CY~zhs3F+YAaRBKe8YnRvRI4ZBMSaR5?_gu}vUkwDWf6ecyZYcHcM8 z;{T=keu+jEK*vbx58YDt`>w&6{jq6f7d+&!`U%Kt`|C9YQ36lr+3x;7AJIo)a7C=R5aP9~d(;}rVSdA0CT-mfU)@r6;7B+XvMmZBgCCi247BNga6jm&2GaCt|^%ZOs z?J#Op?5&EO-&!Yy##Eh-f0cWE4WFVA?xddMFsgGDB3-O}na- za)j2Cp`-CT`b@n;H`nPbBiOhtkA0L(H$Q*!sQzegac}WJ_l5%$-P3p7`cezs@!}_H ze;qYP4-!9)AAHfeK6xCQJW{7x>XerX6wMn7$7|NPXy`99rspCfLz z#m)NMY!HdnN1Lx5M0`2t!`vDD0#LlvQotI{bXq%WQu`fvso(Hwe=+Am2Q1Mbmvebn za7BkB6OM@a4UUF0wFxdXM;#uEJ&)!Hmr#kKDXK+iCMZXK5fyotx>V{?dM+Azx9BW?PmKpopybOpj$pb4(>_cG z199(WFg0@o-}c7qTGKq#10mK1QEogCl|B6BvbP+>SG;L&IzaKdbBsoOG!jUOrf@8! zeJS1MK=QHV-S_Ud1(00e*ea-9P$`~xEMAFcPD-8r_jK^CHxbB5A128Nt#3ZdhqA4g zZFZ#yy90#P|10RAov(Z@zgMzwWmCULCMd+TRsNcqHV+|eOCXjA`WtJJhuOPrFa&$% OjX^ln2Cte<+W!F{m@J*0+IWI340}%A^ZcIHrk#`RlJCMT+#GhwPyqs8{!j{bfk}lGyVTQAnNBv|8i*mFikpD}U96TRk12&Cm?4F;mbHc@g)19uLXl_+cL~UP zD5zmsHo1~fM3kqNHO~{Mj2EtquY`Sa4x=JiMh_^%pAFVhB$gromXYI25v&3V)iUM@ zr3itA6hvxRi&$$IQ-rH{K@v5L!3>%rlP#D`>p^;7g4|nW7@1$Hke8a8qL7qdlA%zZ znwg$aqL7%EqL2Y$mgFlWC*~xV<|LM+DmeLi>ba$ZbTc$qJ5))7G$$6ND&!}n7N_bd z0J%jVH42%<3L!7WLFR+RAWF(oiy)@!DTpI0gc@h$P^CEeAd@HyNN(~~re};QllL%7 zfVrD5Gn+HfQATDNQoP3S(C0sjrZ-`2EaCLCq;N5}S@x*=h` zH~E0_&Wt@77bV<2Ffe#Brm=ivV315>>EP|)eIQ|XRQN#fL5U+07bQF=cd~0M3IUy3 q1ak9Ah9U_NTMS72;;_lhPbtkwwJVaEe3d;^MvPJN0|O=j)&T%DzPe`s delta 550 zcmew+cuatIIWI340}z}KSeI%(k#`RlE0Dts#Gex;UQV{TGkqt6pn0=R)!+c6wVUX$#zT%Vkum;ta+Y5DQ>tF53-aVP>MGjY*dk0 z3LjWXjxUA33Mf>|m?xAX02Wf`6|CX~iPSI#GiVA;E@CpR2RXql9jvv%+M!A;GQU(I zu_#p`KPk01RZqdm*Ha<0SRv%4I8aHIG+eeUwWvHbGd-gOt^{g^kwcXXOjT)K3Wl<( z+X~M4dBvGP8HLQeOY( zatOPbJ(s{#;|XOm5+~YDvAxKp(BOPSP^`i020K?rNK;iq)eQ-Qt;QRQH(G45xF})W z!FxkgvV*IG>jo#!1g0*@4#~-9*rkj+O1h*vq;5! diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc index bfddb8bc37b05a357b667763d42f6e5313698a48..806eb9c65373262e407ba53d28de974a8e04b3c8 100644 GIT binary patch delta 746 zcmZXS&2JJ>6vf{R3(XqKRc|#o>G+n_By?MYl}^-LgrI&6XWw+bOxx^IE84J1 z^IM!r8a7P%C$qjN1)A(%Pv|Me}f&OAeW`jPoB-bFJlpwF^Ai~XT;zACt#D#QCsA?5`Dkug#QOcW&3c9Ek1@wQ8!wv!Xa;3_p2GYYb~}iS_L-6$1-f|@??W- z2sIy|e&o5U7lpV`dp1$?qES}V0u+jsoMy;?b7hjs+SzcVlBiv7l1n7cG|`Z^l}XQ*2oIAbH?b=;#b?Fm=4;~EB`vPZ>YBv?|b72dxBkK&lBl+BB+iCiDcOygv@4H^!&kgs-4;o z#@n}tymv$xuFenbb4V@Jd88b5zU>F-(nKh6JOEo%8< Srya-pV2lZj$p4pq2C3i1=G2A& delta 420 zcmZn_e=NecoR^o20SI)(*QRE2Z{*8jWNesR$@oOuGDWbKDbK8iHAN_!1*D>gt%fN@ zxQds70Vu8oWQ#!ADw8{y6hnn;SW?8ZSwSj`*?_tvAnYR66vTBaK2 zB37VYX^7q$h7=h|kQOii%g91yn1UHJUqs}P#fdP{! I(g3<003CvC`~Uy| diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index de794eedb523822059e44d042a20b8876f25e57a..ee74c2dd467740bde64e8bf38a300353384fb5ca 100644 GIT binary patch delta 1428 zcmZXQT})eL7{||hPP?|}qXk-8YCm=|a0!$Wy299$A!Qw9_!u`Kn%3o{dM^kPd|)5Trsh*yg@H8C+US>p4yT_NmA&U2pk z_dNgq`|;Q4XG!HNMG-lOH^n=t@9!uj#Q!eQKhYC(DZkGrg!lyqIUngN85|DHBV{0oKpg&rVqnGF(*5}b6HQQn+ zMiaI`V5m0l)6ICu%kEnVqfxiv^Yn(zxf`!d@c4ouXldZXHR1%#@DWX7t)eG9<~4-F zMw50C6eEWeBS#d;XB0i4c=@SsI=MY-J2D7|lAui*(=Q9@6>RHAK8* zxbzO@Ks|6eukSWywCg_7@C-&2?|VO%3D3D zs&P)%Jve-DU!1OOcnmgLscqB;^(t&d7ZneEqBv28HrgXyZ?GMzBRYqz2PTzMuGPdn zAYMNz?mk)99e!+fyKJrFp5WTGJhkr%5yGB%<^DYu{z1~sR_RK#43gf1m1~e#VMT`M zd{dC#Y`V^q28x_N4^IGX7utCeg5q%#Tk)imjZRhTFyqavW>X!kbEVpevU--K8ESV0 zyw_Mc&(Z>SyW9fmqqCk+pi^B><#Oug>XN1s2h2VGjwzgwc9!TZPlvlx zofsNd2O?*>)eWM?EA^@F{7;_SDAX~tu|-rsnVg!@z$K+>8zj55u978fC3V<5|DpGD zB<+H40>0co*8Dl&f?zJ&IoU-&4YpWXewC61DM{}J&#RA~^Y4v5baoY-U5^}|g14jO z2z@w;Y7xDyHfZ;oqB@YLFNGm^X?{pEUL=ITAYI67Avoht_B3Jc4{!19CC zY9T`kxy@2$tC-p@rM8QK?V`L*KWdBn*-gIT$h+_(??C#`+MnIPTkEL-@*e%St!!eQ F{{d^qUWotz delta 1672 zcmai!TTCNW7{_O(Q%XBMTY8&Pp)3@4wJn83mR(k$w0q%J_9iNefGlvhNf}@YtB{#s zRufTQ8qZ5N@c~{Gy*HQC+Roe`F;QI ze`d~{>1NL#ar7xd76wLY>5IvhuaU-b53S^P_8<1o%s$s;XkSw-_=P#1N@N3WQUz%V z$a$TFfy@AD)(Hn>6kmWiOnxzTtY4hta^25?szp~dLcIaVC7n?3vp`?iCh!c`rKq5K`t4I=nbm*iB z2!|V0MBXncK1UU3qPm6y%~>EZolqaTR#+$0$3=Z4de`WG?wZG!_0C516nOFY${g>f zkC}S~r{KnUd{q~PK_mdVMsAvFYdXD!4Ph7s74tR3Fseyma2Fw_Gi*2c))ZrV$WxQg z+*@#}AU~8oyRMjVUjcCVx@wT7fZQk$r((o6il(X^YB%R{3(6ekBo>ENhjbn2ts@<` zj&|2kU97aoOlQi;}QHi9{reCUHGo*#un9}m=qTt zBm0&B$y&w_=L_3Y0%lUd>>}g~B!
diK8Le%bXRC)xlj@NnZQcsFK>r4&fBuP%%INe|Zj}F*xT10?)YrVT(!H_7EUuoISx8JKmnY?g zMD>a^yPP~|h5A7wbt zqGXhY5mMpwdB89KeqB73hc8UhBZjjt{ddSwaDn0^1=?xbQ@1+ZEb& zgoq|Y9(i_!?yS&F{_JFcOYCn&OuB0DImq3ENQT@=rvILNyFzgq2C zXZ?<~L9;ewtqs4~JXvp0vxT<%G~1;O9u_0RRpo7O?h2h*p>xmXOpSlAy0N;sln$nY zdvE7eh)77b9-r$by*gBc-s;(KtE_MU$nQSSfnX1x?W~w`6EXEFU z#y?t;ty$bDTO=v}hkRtm8Xcd DFIblp diff --git a/anaemia.py b/anaemia.py index 756728950d37..892e2dd24e26 100644 --- a/anaemia.py +++ b/anaemia.py @@ -24,49 +24,29 @@ #mcv need fl RBC need 10^6/uL #returns tuple - bool whether anaemia, and bool whether iron deficient def anaemia_analysis (hbdict): - output_phrase = "i didn't catch that" + output_phrase = "I didn't catch that" print ("in anaemia analysis") hblevel = hbdict["hb"]["test_value"] - emergency = True if hblevel < 7 else False - mcv = hbdict["mcv"]["test_value"] - anaemia = bool(hblevel < hbdict["hb"]["test_ref_min"]) - antype = "" - iron = False - if anaemia: - if mcv < hbdict["mcv"]["test_ref_min"]: + if hblevel < 7: + return "Your haemoglobin level is dangerously low. Please visit a doctor immediately." + if hblevel < hbdict["hb"]["test_ref_min"]: + if not hbdict["mcv"]["test_found"] or not hbdict["rbc_count"]["test_found"]: + return "You have anaemia, but there is not enough information to determine the cause. Visit a doctor if you have any concerns of blood loss." + mcv = hbdict["mcv"]["test_value"] + if mcv < hbdict["mcv"]["test_ref_min"]: #microcytic mentzer = mcv/ hbdict["rbc_count"]["test_value"] if mentzer > 13: - iron = True - else : - iron = False - antype = "microcytic" - elif mcv > hbdict["mcv"]["test_ref_max"]: - antype = "macrocytic" - else: - antype = "normocytic" - print(f"result of analysis {anaemia, antype, iron, emergency}\n") - return (anaemia, antype, iron, emergency) - -def get_anaemia_advice (input_tuple): - print ("in anaemia advice") - output_phrase = "" - (anaemia_bool, anaemia_type, iron_deficient, emerg) = input_tuple - if anaemia_bool: - if emerg == True: - output_phrase = "Your haemoglobin level is dangerously low. Please visit a doctor immediately." - elif anaemia_type == "microcytic": - if iron_deficient == True: output_phrase = "you have anaemia, which could be due to iron deficiency. This can be caused by minor bleeding e.g. menstruation, or from the gastrointestinal tract. Visit your doctor for an assessment to rule out sources of bleeding. Consider taking iron supplements and foods rich in iron, such as green leafy vegetables, meat, especially red meat (beef, mutton, pork), seafood, and organs (kidney, liver)." - else: - output_phrase = "you have anaemia, which could be related to genetic conditions such as thalassaemia. Visit your doctor for an assessment." - elif anaemia_type == "macrocytic": + else : + output_phrase = "you have anaemia, which could be related to genetic conditions such as thalassaemia. Visit your doctor for an assessment." + elif mcv > hbdict["mcv"]["test_ref_max"]: # macrocytic output_phrase = "you have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." - elif anaemia_type == "normocytic": + else: #normocytic output_phrase = "you have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." else: - output_phrase = "you don't have anaemia." - return output_phrase + output_phrase = "You don't have anaemia." + return output_phrase -#print (f"here is result: {get_anaemia_advice(anaemia_analysis (testdict))}") +#print (f"here is result: {anaemia_analysis (testdict)}") diff --git a/bmi.py b/bmi.py index cefff14025fd..687e3b5220f4 100644 --- a/bmi.py +++ b/bmi.py @@ -21,18 +21,21 @@ def bmi_advice(test_results): output_string = "I didn't catch that" weight = test_results["weight"]["test_value"] height = test_results["height"]["test_value"] - bmi = weight / pow(height,2) + if weight > 0 and height > 0: + bmi = round(weight / pow(height,2), 2) + else: + return "You need both weight and height to calculate BMI." weightloss = False if bmi >=27.5: - output_string = "You are obese. BMI is " + str(bmi) + output_string = "You are obese. Your BMI is " + str(bmi) weightloss = True elif bmi >= 23: - output_string = "You are overweight. BMI is " + str(bmi) + output_string = "You are overweight. Your BMI is " + str(bmi) weightloss = True elif bmi < 18.5: - output_string = "You are underweight. BMI is " + str(bmi)+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." + output_string = "You are underweight. Your BMI is " + str(bmi)+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." else: - output_string = "You have a healthy BMI. BMI is " + str(bmi) + output_string = "You have a healthy BMI. Your BMI is " + str(bmi) if weightloss: output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string diff --git a/diabetes.py b/diabetes.py index 66469b7678fe..958a5eb5e26a 100644 --- a/diabetes.py +++ b/diabetes.py @@ -45,29 +45,33 @@ def get_dm_advice(inputattributes, inputdict): else: a1ctarget = 7.0 if a1c_value > a1ctarget: - output_phrase = "your HbA1c is above target, your diabetes can be controlled better." + output_phrase = "your HbA1c is above target, your diabetes can be controlled better. Aim for a HbA1c <7." lifestyle = True else: - output_phrase = "your HbA1c is within range." + output_phrase = "your HbA1c is within range for a diabetic, <7." else: if glucose_value > 6: - output_phrase += "\nyour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." + output_phrase += "\nYour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." else: - output_phrase += "\nyour fasting glucose level is within range." + output_phrase += "\nYour fasting glucose level is within range, <6." else: #diagnose dm if a1c_value >= 6.5 or glucose_value >= 7: - output_phrase = "you have diabetes. Consult a doctor for advice, you may need to be started on medications." + output_phrase = "You have diabetes. Consult a doctor for advice, you may need to be started on medications." lifestyle = True elif a1c_value >= 5.7 or glucose_value >=5.6: - output_phrase = "you have prediabetes." + output_phrase = "You have prediabetes." + if a1c_value >= 5.7: + output_phrase += " Your HbA1c is >5.7." + if glucose_value >=5.6: + output_phrase += " Your fasting glucose is >5.6. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." lifestyle = True else: - output_phrase = "you do not have diabetes." + output_phrase = "You do not have diabetes." if lifestyle: - output_phrase += "Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein, and half with fruit and vegetables). Maintain a healthy weight BMI ranging from 18.5 to 22.9 kg/m2. Exercise regularly, aiming for 150 minutes of moderate-intensity activity per week or 20 minutes of vigorous-intensity activity 3 or more days a week). Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + output_phrase += " Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein, and half with fruit and vegetables). Maintain a healthy weight BMI ranging from 18.5 to 22.9 kg/m2. Exercise regularly, aiming for 150 minutes of moderate-intensity activity per week or 20 minutes of vigorous-intensity activity 3 or more days a week). Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if inputattributes["smoker"]: - output_phrase += "Quit smoking." + output_phrase += " Quit smoking." return output_phrase #print(f"advice {get_dm_advice(test_attributes, testdict)}") \ No newline at end of file diff --git a/lipids_ranges.py b/lipids_ranges.py index f9833ffb242e..7e85fc7a4ffb 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -186,7 +186,7 @@ def getLDLBPtarget (attributes,testvals): cholbracket = -1 return "invalid cholesterol units" - # hval = testvals ["hdl_cholesterol"]["test_value"] + hval = testvals ["hdl_cholesterol"]["test_value"] # if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": # if hval > 59: hdlbracket = 0 # elif hval > 49: hdlbracket = 1 @@ -286,18 +286,18 @@ def getLDLBPtarget (attributes,testvals): output_phrase += "You may require cholesterol lowering medications, consult your doctor. " else: - output_phrase = "Your LDL cholesterol is within target range." + output_phrase = "Your LDL cholesterol is within target range, less than " + str(LDLtargetcalc) if testvals["systolic_bp"]["test_found"]: bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic_bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: if bp[0] > 180 or bp[1] > 120: - output_phrase += " \n Your blood pressure is dangerously high. Visit a doctor for assessment.\n" + output_phrase += " \n Your blood pressure is dangerously high, SBP >180 or DBP >120. Visit a doctor for assessment.\n" else: output_phrase += "\n Your blood pressure is high. Your target should be " + str(BP_target[0]) + "/" + str(BP_target[1]) + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: - output_phrase += "your BP is in the normal range." + output_phrase += "Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) if attributes["smoker"]: output_phrase += "\nQuit smoking." return output_phrase diff --git a/streamlit_app.py b/streamlit_app.py index ab37fc26525f..bc28ec7dc5f8 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -98,9 +98,9 @@ for key, value in test_results.items(): print (f"looking at {key} and {value}") if value["test_found"]: - if key == "mcv": - print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") - st.write (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") + if key == "hb": + print (f"FBC {anaemia_analysis (test_results)}") + st.write (f"FBC {anaemia_analysis (test_results)}") elif key == "ldl_cholesterol": st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") diff --git a/testing.py b/testing.py index 159e93715a04..e3d0ff808f2e 100644 --- a/testing.py +++ b/testing.py @@ -1,7 +1,7 @@ from lipids_ranges import getLDLBPtarget from diabetes import get_dm_advice -from anaemia import anaemia_analysis, get_anaemia_advice +from anaemia import anaemia_analysis from bmi import bmi_advice test_attributes = { @@ -24,8 +24,8 @@ 'mcv': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, 'hb': {'test_found': True, 'test_value': 15.6, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, 'rbc_count': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, - 'glucose': {'test_found': True, 'test_value': 5.3, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, - 'hba1c': {'test_found': True, 'test_value': 5.8, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, + 'glucose': {'test_found': True, 'test_value': 9, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, + 'hba1c': {'test_found': True, 'test_value': 8, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, 'systolic_bp': {'test_found': True, 'test_value': 141, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'diastolic_bp': {'test_found': True, 'test_value': 73, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, @@ -35,14 +35,14 @@ for key, value in test_results.items(): print (f"looking at {key} and {value}") if value["test_found"]: - if key == "mcv": - print (f"FBC {get_anaemia_advice(anaemia_analysis (test_results))}") + if key == "hb": + print (f"FBC {anaemia_analysis (test_results)}") elif key == "ldl_cholesterol": print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") elif key == "glucose": print (f"glucose {get_dm_advice(test_attributes, test_results)}") elif key == "systolic_bp": - if not test_results["ldl_cholesterol"]["test_found"]: + if not test_results["total_cholesterol"]["test_found"] or not test_results["hdl_cholesterol"]["test_found"]: print("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") elif key == "weight": print (f"BMI {bmi_advice(test_results)}") \ No newline at end of file From a683546a357376b5c1a3a854fd5beccbbff35621 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Wed, 24 Jan 2024 21:22:36 +0800 Subject: [PATCH 120/164] capitalisation --- diabetes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diabetes.py b/diabetes.py index 958a5eb5e26a..3acc82a240ca 100644 --- a/diabetes.py +++ b/diabetes.py @@ -31,7 +31,7 @@ def get_dm_advice(inputattributes, inputdict): print ("in dm advice") - output_phrase = "i didn't catch that" + output_phrase = "I didn't catch that." lifestyle = False #known dm a1c_value = inputdict["hba1c"]["test_value"] From 8a1cc3726d3133d4efa3c39ea6099aa58a82d17a Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Thu, 25 Jan 2024 20:36:57 +0800 Subject: [PATCH 121/164] catch more exceptions --- __pycache__/diabetes.cpython-311.pyc | Bin 2949 -> 2950 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 9376 -> 9586 bytes lipids_ranges.py | 14 +++++++++++--- streamlit_app.py | 2 +- testing.py | 12 ++++++------ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc index 806eb9c65373262e407ba53d28de974a8e04b3c8..7187dac2be7570345794b97a7d7aa6a72360c09b 100644 GIT binary patch delta 64 zcmZn_ZxiQT&dbZi00hGP8&h|0c2qRNv R^&8D1zOaLk_5oG`X diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index ee74c2dd467740bde64e8bf38a300353384fb5ca..3f3c12e531c4d1cc81a87f94a9df6431a32fca7b 100644 GIT binary patch delta 1477 zcmZuwOKclO7~Wm4zzuml=Z9^N}#E;Z2AvA3sBq~XZRGLuIG>Ky2;DPJsrVUK8n_j6rIDS})6aiAZc#x-Z_S z97%mP>m(R_>{n}yjX2uGUUt=S@sx!m%04j8%?jjIa+AD9=EWa zF;;cBS1{<2%E7#s5cak6wy1MYzw7qknpr@>RSJ>FlR`yOx6L&T@)bYmmB^pQlS?+-dcOe|7#oS>zEY>#*6;3=YxG=k!8oMNXkKRkkQ_EFauFDSFd$B8kX zwz=|;(N^@2vn|im@+8tOgeib+UmT z0QGTXmyr!2!#33;$S$!H-eobu-t=~_ZZFKOXA4?7l}m5sQbmJmu*w@n?Tu6}OHxIh zXlo!E#dY{HO{MihRGZFg89lGlRBk{^WjC~Ilh?G7L^P?T@&rz&jSME^vEg_$Y=LH8 zWFL6XEaIinO90Tn7w{lK6mFnk0qGn{UR;^4gWfbbzu&;Ii@)qSGs54~0&qIdI(^;k zi%6FcmH{#eKAdB8rSgie!?yDdh*#iOIBOS#UEvqmzBl@#+*y-5t8(XoKd}4qfjhW6 zeP~l3C^g&3hozcrpdnbTo&z=Xu)C)Aed?;I7xv^m`M~b0`Xe=av>{lmp3i5hqw}@o zt?J^^Psycfa_K;AuXZGAY7)JNsv9=gJP#`0cElyoUHQGMS8m*mJrOaQdW%0I;hzIyNn0dqentH0Ad>#TdNuUy8S=ouXL8Hqy>GOW@;l z_!_}4(erqMV)ibraIG8_g_iMzo&rHPaZWEn;LhX%9WQN5q5;(X+yfczLO3alwf%}; z((x{76#%TkU1$+zBp!?+m4dJ)&`Vr~LUXb|C z$pc*m7nr$(%>mwK1b%FzIS2AInL9{<|Gc%ErbC+6vRHcNS+q<|@^QME*GSGXnrSN9 zTG`w5_E0<09E2+XE3U}IA`Sb-CYQt1*V<$gGA!kUuz;>OvCcg})YhZP*!XfSof&mUxk7f^=dr*);Dn`kPGvm5wpTT*< z-6t;otMwWge!+vlX+PU_<$8yah7d*orYiWbHq+7gcUPAA<{F4s;f)+aBVxj5<iRI0s2bR_F0a=-9!^*bHoFqmz#crKGkdd< z#OQLY?Q8sDc7-IW@!i}4C4QJ6m2z;8ErG@$&{cq6sSWds 0 : + bval = attributes["systolic_blood_pressure"] + else: + bval = 0 if(attributes["stroke"]): LDLtargetcalc = 1.8 BP_target = (140, 90) #with disclaimer @@ -92,11 +97,12 @@ def getLDLBPtarget (attributes,testvals): if not all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): print ("something missing "+str((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]))) print(bool(bval), bool(attributes["age"]), bool (attributes["sex"]), bool(attributes["race"]), bool(testvals["total_cholesterol"]["test_value"]), bool(testvals ["hdl_cholesterol"]["test_value"])) - return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above. In general, BP <140/90 and LDL <3.4 if no other risk factors." + return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). In general, BP <140/90 and LDL <3.4 if no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; # total chol as tuple ((4, 4), (7, 8), (9, 11), (11, 13)) for 4.1-5.1 : M 4 F 4, 5.2-6.1 : M 7 F 8, 6.2-7.2 : M 9 F 11, >7.3 : M 11 F 13 + agedict = { 20 : { "age": ( @@ -258,6 +264,8 @@ def getLDLBPtarget (attributes,testvals): raceint = 1 elif attributes["race"].lower() == "chinese": raceint = 2 + else: + return "This calculator is not validated for other races. In general, aim LDL <3.4 and BP <140/90." #matching to cardiovascular risk bracket cvriskdict = { diff --git a/streamlit_app.py b/streamlit_app.py index bc28ec7dc5f8..01cbf9217bfd 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -12,7 +12,7 @@ from chatgpt_values import extract_values from lipids_ranges import getLDLBPtarget from diabetes import get_dm_advice -from anaemia import anaemia_analysis, get_anaemia_advice +from anaemia import anaemia_analysis from bmi import bmi_advice #from dotenv import load_dotenv diff --git a/testing.py b/testing.py index e3d0ff808f2e..5b79c195365b 100644 --- a/testing.py +++ b/testing.py @@ -6,7 +6,7 @@ test_attributes = { "age":57, - "sex":"Female", + "sex":"male", "race":"Chinese", "smoker":False, "stroke":False, @@ -22,12 +22,12 @@ 'hdl_cholesterol': {'test_found': True, 'test_value': 1, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, 'total_cholesterol': {'test_found': True, 'test_value': 3.7, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, 'mcv': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, - 'hb': {'test_found': True, 'test_value': 15.6, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, + 'hb': {'test_found': False, 'test_value': False, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, 'rbc_count': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, - 'glucose': {'test_found': True, 'test_value': 9, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, - 'hba1c': {'test_found': True, 'test_value': 8, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, - 'systolic_bp': {'test_found': True, 'test_value': 141, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, - 'diastolic_bp': {'test_found': True, 'test_value': 73, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, + 'glucose': {'test_found': False, 'test_value': False, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, + 'hba1c': {'test_found': False, 'test_value': False, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, + 'systolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, + 'diastolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, 'weight': {'test_found': True, 'test_value': 58, 'test_unit': 'kg', 'test_ref_min': False, 'test_ref_max': False} } From 832790a363b24ac3b4563d2a3451b10ec989af11 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Thu, 25 Jan 2024 22:44:03 +0800 Subject: [PATCH 122/164] convert cholesterol to mmol/L --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index a7933aae8b18..016fb9e6048d 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -11,7 +11,7 @@ template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres and weight to kg. +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres, weight to kg, cholesterol to mmol/L. Example output json template { From fd74a89fbdb8ab0e28ff9c5f715a2dff20f908f8 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Thu, 25 Jan 2024 23:11:32 +0800 Subject: [PATCH 123/164] Update streamlit_app.py --- streamlit_app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 01cbf9217bfd..6152508a4987 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -17,13 +17,13 @@ #from dotenv import load_dotenv #load_dotenv() -API_KEY = os.environ['API_KEY'] # API_KEY in secret +API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) ocr_model = PaddleOCR(use_angle_cls=True, lang='en') -tab1, tab2 = st.tabs(["Main", "More Info"]) +tab1, tab2 = st.tabs(["Main", "About"]) test_attributes = {} @@ -115,6 +115,7 @@ with tab2: + st.markdown("**Lab-Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab-Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") st.header('Lab measurements included for analysis') st.markdown(measurements_list) st.write('Other lab tests will be added soon...stay tuned!') From deb1da6ab29762da3fded6fcde19dfdd7910e181 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 00:17:59 +0800 Subject: [PATCH 124/164] personal report --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index 6152508a4987..f3b112c4cf59 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -41,7 +41,7 @@ with tab1: st.title('Explain my test results please!') - st.subheader('Answer the questions, take a picture of your lab test results, and get your results explained!') + st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately!') # User inputs age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") From cd6153b9a2c6f7d51130b944b3d030dd40564d0c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 00:20:03 +0800 Subject: [PATCH 125/164] Update streamlit_app.py --- streamlit_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streamlit_app.py b/streamlit_app.py index f3b112c4cf59..33638bae6618 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -40,7 +40,7 @@ """ with tab1: - st.title('Explain my test results please!') + st.title('LAB-LOKUN') st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately!') # User inputs From f1069f4ff7dd8a12c51aa632d103eccaa4e3d047 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:28:21 +0800 Subject: [PATCH 126/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 33638bae6618..808819b42da4 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -40,7 +40,7 @@ """ with tab1: - st.title('LAB-LOKUN') + st.title('LAB LOKUN') st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately!') # User inputs @@ -115,7 +115,7 @@ with tab2: - st.markdown("**Lab-Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab-Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") + st.markdown("**Lab Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") st.header('Lab measurements included for analysis') st.markdown(measurements_list) st.write('Other lab tests will be added soon...stay tuned!') From cdc0db4492fee9bfc6adf05123d8b638e5bae0e4 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:57:11 +0800 Subject: [PATCH 127/164] update model to gpt-3.5-turbo --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 016fb9e6048d..f593dbc9e09a 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -108,7 +108,7 @@ def extract_values(client,extracted_text): extract_start_time = time.time() extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( - model="gpt-3.5-turbo-1106", + model="gpt-3.5-turbo", response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, From 9fd13ed3e18b8535adb6a87495d2fb6c8ae97ca0 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:58:53 +0800 Subject: [PATCH 128/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index f593dbc9e09a..016fb9e6048d 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -108,7 +108,7 @@ def extract_values(client,extracted_text): extract_start_time = time.time() extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( - model="gpt-3.5-turbo", + model="gpt-3.5-turbo-1106", response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, From 7e581fc11158d23cab4223fd3ae38abd45aeb142 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:05:48 +0800 Subject: [PATCH 129/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 016fb9e6048d..dae0d0b361cb 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -11,7 +11,7 @@ template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres, weight to kg, cholesterol to mmol/L. +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres, weight to kg, cholesterol to mmol/L, and leave other test units as original. Example output json template { From fa60efe6f44a14f3df30320144340a618025d798 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:10:26 +0800 Subject: [PATCH 130/164] Update image_loading.py --- image_loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_loading.py b/image_loading.py index 6d11b2694541..77f9af31a4e7 100644 --- a/image_loading.py +++ b/image_loading.py @@ -25,7 +25,7 @@ def remove_nric(text): def extract_text(image,ocr_model): ocr_start_time = time.time() result = ocr_model.ocr(image) - #result = result[0] #idk why this needs a result[0] instead of result for Github + result = result[0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From cd49ab2c21954669bfcd6c9d67fbb480d9cc3dd5 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:38:26 +0800 Subject: [PATCH 131/164] Update chatgpt_values.py --- chatgpt_values.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index dae0d0b361cb..336dad188122 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -11,8 +11,7 @@ template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres, weight to kg, cholesterol to mmol/L, and leave other test units as original. - +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres and weight to kg. Example output json template { "ldl_cholesterol": { From 992bdb6896ff9393e95cfd1ec6adea37267169e9 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:40:25 +0800 Subject: [PATCH 132/164] Update streamlit_app.py --- streamlit_app.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 808819b42da4..dc140a082694 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -95,23 +95,36 @@ print (test_results) print (test_attributes) #test_results test_attributes + full_output = "" for key, value in test_results.items(): print (f"looking at {key} and {value}") if value["test_found"]: if key == "hb": - print (f"FBC {anaemia_analysis (test_results)}") - st.write (f"FBC {anaemia_analysis (test_results)}") + fbc_output = anaemia_analysis (test_results) + print (f"FBC {fbc_output}") + st.write (f"FBC {fbc_output}") + full_output += f"FBC {fbc_output}\n" elif key == "ldl_cholesterol": - st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") - print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") + chol_output = getLDLBPtarget (test_attributes, test_results) + print (f"LDL/BP {chol_output}") + st.write (f"LDL/BP {chol_output}") + full_output += f"LDL/BP {chol_output}\n" elif key == "glucose": - st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") - print (f"glucose {get_dm_advice(test_attributes, test_results)}") + glucose_output = get_dm_advice(test_attributes, test_results) + st.write (f"glucose {glucose_output}") + print (f"glucose {glucose_output}") + full_output += f"glucose {glucose_output}\n" elif key == "systolic_bp": if not test_results["ldl_cholesterol"]["test_found"]: - st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") + bp_output = "we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90." + st.write(f"BP {bp_output}") + full_output += f"BP {bp_output}\n" elif key == "weight": - st.write (f"BMI {bmi_advice(test_results)}") + bmi_output = bmi_advice(test_results) + st.write (f"BMI {bmi_output}") + full_output += f"BMI {bmi_output}\n" + print(full_output) + st.markdown(full_output) with tab2: From 03487be2153f4d8cab3f0ed6b763c86e1542c381 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:55:25 +0800 Subject: [PATCH 133/164] Update chatgpt_values.py --- chatgpt_values.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 336dad188122..90074b0df522 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -11,7 +11,9 @@ template_prompt = """ -Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". Convert height to metres and weight to kg. +Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". +Convert height to metres, weight to kg, and LDL HDL and total cholesterol to mmol/L. + Example output json template { "ldl_cholesterol": { From ca5fed429cc19db25c99651a426a6b5959c93495 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Fri, 26 Jan 2024 23:56:19 +0800 Subject: [PATCH 134/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 90074b0df522..fce708f0a181 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -12,7 +12,7 @@ template_prompt = """ Extract the items from the health screening result listed below into a json format, using the example json template. Ignore other items not listed in the json template. Output data types are "test_found" (True/False), "test_value" (float), "test_unit" (string), "test_ref_min" (float), "test_ref_max" (float). If test item is not found, output False for "test_found", and output False for the other values. If test is found but reference max, reference min, or reference range is not found, output False for "test_ref_min" and "test_ref_max". -Convert height to metres, weight to kg, and LDL HDL and total cholesterol to mmol/L. +Convert height to metres and weight to kg. Example output json template { From 268ffb77cffcd02b904f95af67ef8c98abe7b393 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:49:44 +0800 Subject: [PATCH 135/164] Update streamlit_app.py --- streamlit_app.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index dc140a082694..f6121940dc3a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -102,29 +102,27 @@ if key == "hb": fbc_output = anaemia_analysis (test_results) print (f"FBC {fbc_output}") - st.write (f"FBC {fbc_output}") - full_output += f"FBC {fbc_output}\n" + full_output += f"**FBC** \n{fbc_output} \n\n" # streamlit needs 2 whitespace before newline char elif key == "ldl_cholesterol": chol_output = getLDLBPtarget (test_attributes, test_results) print (f"LDL/BP {chol_output}") - st.write (f"LDL/BP {chol_output}") - full_output += f"LDL/BP {chol_output}\n" + full_output += f"**LDL/BP** \n{chol_output} \n\n" elif key == "glucose": glucose_output = get_dm_advice(test_attributes, test_results) - st.write (f"glucose {glucose_output}") - print (f"glucose {glucose_output}") - full_output += f"glucose {glucose_output}\n" + full_output += f"**Glucose** \n{glucose_output} \n\n" elif key == "systolic_bp": if not test_results["ldl_cholesterol"]["test_found"]: - bp_output = "we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90." - st.write(f"BP {bp_output}") - full_output += f"BP {bp_output}\n" + bp_output = "We need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90. \n\n" + full_output += f"**BP** \n{bp_output}\n" elif key == "weight": bmi_output = bmi_advice(test_results) - st.write (f"BMI {bmi_output}") - full_output += f"BMI {bmi_output}\n" + full_output += f"**BMI** \n{bmi_output} \n\n" print(full_output) - st.markdown(full_output) + if full_output == "": # if no supported lab results found + full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in our About page." + st.error(f"{full_output}",icon="🚨") + else: + st.markdown(full_output) with tab2: From 00bceecb70235012bc7c400e2f0725d73bafabb1 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:51:25 +0800 Subject: [PATCH 136/164] Update chatgpt_values.py --- chatgpt_values.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index fce708f0a181..92efcf837cb8 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -17,23 +17,23 @@ Example output json template { "ldl_cholesterol": { - "test_found":True, - "test_value":20, - "test_unit":"mmol/l", + "test_found":False, + "test_value":False, + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, "hdl_cholesterol": { "test_found":True, - "test_value":20, - "test_unit":"mmol/l", + "test_value":False, + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, "total_cholesterol": { - "test_found":True, - "test_value":20, - "test_unit":"mmol/l", + "test_found":False, + "test_value":False, + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, From e20178133c94755cfa970edc3f2dbe9c3fd97716 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 28 Jan 2024 15:07:17 +0800 Subject: [PATCH 137/164] catch non existent --- __pycache__/diabetes.cpython-311.pyc | Bin 2950 -> 2959 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 9586 -> 9628 bytes bmi.py | 4 +++- diabetes.py | 14 ++++++------ lipids_ranges.py | 26 ++++++++++++---------- streamlit_app.py | 21 +++++++++++------ testing.py | 6 ++--- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc index 7187dac2be7570345794b97a7d7aa6a72360c09b..8e0dc90ca42fc502df64a750af1a9238eb1a3407 100644 GIT binary patch delta 219 zcmZn@?-%D@&dbZi00bdlwr=EJ$5bz#%?jccNvBBEGS#r8NJ9CnHB2c|RlE!gKvC8d zX(Uk@h-ivHEpr}IiY!o`xd^0M4yu|VMP3qQBp85Y6reIp!3>&;epNh~c?v1H3W+IY znaP_in9Z2j)4)JtaviILM*7(^ARy*YC87|SUs|N#k>qHYtdLo(U}vUhpqCC&E9NkH P4XX?@P-OFI*4?ZC=bbjM delta 252 zcmeAdZxiQU&dbZi00hGP8#i*VW2%?PW(9GJq*EkonQB;4#G!oF8m1JfDqaQ#peSn! zOch8}8X}q^P|KXhlp+I^XD$MX%R*H%q{vBvj06L)j676^DVRZ1!LN!ZGfyEUS0OQ_ zEHint1+y7b?AbFQAm)&s1_ojdRicskr3x8|WvL1UMX4#7iAkv?sl|F#A__q9A_b2m rN5f==%wh#QQ$2INsyc{hT4HfYW?s5NdQNF_esL;P-fZ&~*4?ZCNx(wy diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index 3f3c12e531c4d1cc81a87f94a9df6431a32fca7b..b0cb594d0a313da699fb3af9aeaaa71766bffb0f 100644 GIT binary patch delta 97 zcmez5HOHH8IWI340}vb!-IS_iypeAOALFgb+xZH$6f_dkQ*{)IQ!8{7iV~AS%*x`D y{G7~Wg`}MP{1k 0 and height > 0: bmi = round(weight / pow(height,2), 2) else: - return "You need both weight and height to calculate BMI." + return"I need both your weight and height to calculate your BMI." weightloss = False if bmi >=27.5: output_string = "You are obese. Your BMI is " + str(bmi) diff --git a/diabetes.py b/diabetes.py index 3acc82a240ca..2381c6b34345 100644 --- a/diabetes.py +++ b/diabetes.py @@ -34,10 +34,10 @@ def get_dm_advice(inputattributes, inputdict): output_phrase = "I didn't catch that." lifestyle = False #known dm - a1c_value = inputdict["hba1c"]["test_value"] - glucose_value = inputdict["glucose"]["test_value"] + a1c_value = inputdict["hba1c"]["test_value"] if inputdict["hba1c"]["test_found"] else 0 + glucose_value = inputdict["glucose"]["test_value"] if inputdict["glucose"]["test_found"] else 0 if inputattributes["diabetes"]: - if inputdict["hba1c"]["test_found"]: + if a1c_value >0: if inputattributes["age"] >= 80: a1ctarget = 8 elif inputattributes["age"] <=40: @@ -49,7 +49,7 @@ def get_dm_advice(inputattributes, inputdict): lifestyle = True else: output_phrase = "your HbA1c is within range for a diabetic, <7." - else: + if glucose_value >0: if glucose_value > 6: output_phrase += "\nYour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." else: @@ -59,12 +59,12 @@ def get_dm_advice(inputattributes, inputdict): if a1c_value >= 6.5 or glucose_value >= 7: output_phrase = "You have diabetes. Consult a doctor for advice, you may need to be started on medications." lifestyle = True - elif a1c_value >= 5.7 or glucose_value >=5.6: + elif a1c_value >= 6.1 or glucose_value >=6.1: output_phrase = "You have prediabetes." if a1c_value >= 5.7: - output_phrase += " Your HbA1c is >5.7." + output_phrase += " Your HbA1c is >6.0." if glucose_value >=5.6: - output_phrase += " Your fasting glucose is >5.6. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." + output_phrase += " Your fasting glucose is >6.0. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." lifestyle = True else: output_phrase = "You do not have diabetes." diff --git a/lipids_ranges.py b/lipids_ranges.py index ad0e855f4a73..95c8d522877c 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -97,7 +97,7 @@ def getLDLBPtarget (attributes,testvals): if not all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): print ("something missing "+str((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]))) print(bool(bval), bool(attributes["age"]), bool (attributes["sex"]), bool(attributes["race"]), bool(testvals["total_cholesterol"]["test_value"]), bool(testvals ["hdl_cholesterol"]["test_value"])) - return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). In general, BP <140/90 and LDL <3.4 if no other risk factors." + return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). We also need your HDL cholesterol and total cholesterol. In general, BP <140/90 and LDL <3.4 if no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; @@ -176,12 +176,10 @@ def getLDLBPtarget (attributes,testvals): sex = 0 if attributes["sex"].lower() == "male" else 1 age = attributes["age"] tcval = testvals ["total_cholesterol"]["test_value"] - # if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": - # if tcval > 280: cholbracket = 3 - # elif tcval > 240: cholbracket = 2 - # elif tcval > 200: cholbracket = 1 - # elif tcval > 160: cholbracket = 0 - # else: cholbracket = -1 + if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + tcval *= 0.02586 + testvals ["total_cholesterol"]["test_value"] *= 0.02586 + testvals ["total_cholesterol"]["test_unit"] = "mmol/L" if testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": if tcval > 7.2: cholbracket = 3 elif tcval > 6.1: cholbracket = 2 @@ -193,11 +191,10 @@ def getLDLBPtarget (attributes,testvals): return "invalid cholesterol units" hval = testvals ["hdl_cholesterol"]["test_value"] - # if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": - # if hval > 59: hdlbracket = 0 - # elif hval > 49: hdlbracket = 1 - # elif hval > 40: hdlbracket = 2 - # else: hdlbracket = 3 + if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + hval *= 0.02586 + testvals ["hdl_cholesterol"]["test_value"] *= 0.02586 + testvals ["hdl_cholesterol"]["test_unit"] = "mmol/L" if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": if hval > 1.5: hdlbracket = 0 elif hval > 1.2: hdlbracket = 1 @@ -288,6 +285,11 @@ def getLDLBPtarget (attributes,testvals): recmeds = False #print (f"score {score} LDL target {LDLtargetcalc}") + if not testvals ["ldl_cholesterol"]["test_found]: + return "LDL cholesterol not found. LDL cholesterol is the main cholesterol that affects medical management." + if testvals ["ldl_cholesterol"]["test_unit"].lower() =="mg/dl": + testvals ["ldl_cholesterol"]["test_value"] *= 0.02586 + testvals ["ldl_cholesterol"]["test_unit"] = "mmol/L" if testvals ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if recmeds: diff --git a/streamlit_app.py b/streamlit_app.py index 01cbf9217bfd..8165e7ff2f30 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -96,6 +96,10 @@ print (test_attributes) #test_results test_attributes for key, value in test_results.items(): + dm = False + anaemia = False + LDLBP = False + BMI = False print (f"looking at {key} and {value}") if value["test_found"]: if key == "hb": @@ -104,15 +108,18 @@ elif key == "ldl_cholesterol": st.write (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") print (f"LDL/BP {getLDLBPtarget (test_attributes, test_results)}") - elif key == "glucose": - st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") - print (f"glucose {get_dm_advice(test_attributes, test_results)}") + elif key == "glucose" or key == "hba1c": + if not dm: + st.write (f"glucose {get_dm_advice(test_attributes, test_results)}") + print (f"glucose {get_dm_advice(test_attributes, test_results)}") + dm = True elif key == "systolic_bp": - if not test_results["ldl_cholesterol"]["test_found"]: + if not test_results["hdl_cholesterol"]["test_found"]: st.write("we need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90.") - elif key == "weight": - st.write (f"BMI {bmi_advice(test_results)}") - + elif key == "weight" or key == "height": + if not BMI: + st.write (f"BMI {bmi_advice(test_results)}") + BMI = True with tab2: st.header('Lab measurements included for analysis') diff --git a/testing.py b/testing.py index 5b79c195365b..fb46b95d5fe6 100644 --- a/testing.py +++ b/testing.py @@ -14,7 +14,7 @@ "heart_attack":False, "ckd":False, "on_BP_meds":False, - "systolic_blood_pressure": None + "systolic_blood_pressure": 120 } test_results = { @@ -22,10 +22,10 @@ 'hdl_cholesterol': {'test_found': True, 'test_value': 1, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, 'total_cholesterol': {'test_found': True, 'test_value': 3.7, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, 'mcv': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, - 'hb': {'test_found': False, 'test_value': False, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, + 'hb': {'test_found': False, 'test_value': False, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, 'rbc_count': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, 'glucose': {'test_found': False, 'test_value': False, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, - 'hba1c': {'test_found': False, 'test_value': False, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, + 'hba1c': {'test_found': True, 'test_value': 6.0, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, 'systolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'diastolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, From a03e126851b79854a0591920e75dc0e0829cde5e Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 28 Jan 2024 16:58:48 +0800 Subject: [PATCH 138/164] quotation mark --- __pycache__/bmi.cpython-311.pyc | Bin 2294 -> 2410 bytes __pycache__/chatgpt_values.cpython-311.pyc | Bin 3762 -> 3763 bytes __pycache__/diabetes.cpython-311.pyc | Bin 2959 -> 3062 bytes __pycache__/image_loading.cpython-311.pyc | Bin 2044 -> 2069 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 9628 -> 10573 bytes lipids_ranges.py | 2 +- 6 files changed, 1 insertion(+), 1 deletion(-) diff --git a/__pycache__/bmi.cpython-311.pyc b/__pycache__/bmi.cpython-311.pyc index e89af4c018a94f434c4648ff43c540e237e59a90..6b4afddfa7ede276c74fa6f5cc37273688d167e1 100644 GIT binary patch delta 431 zcmew+_)3UxIWI340}$N$x;3?iVO28Pu@3;|W#3=An~Vzn%J zU>j1nYFTSoQn<5OL28RcQ+Or|Fe!-DGN$m>vgUaLrTE}d{K!&zKq-N2umwe8DS|*L zMQ))gAitI|Pbftgq;zr&6DO}o6)#AvhB25yQ*?3>leRR-T}2!~qRP@!AulyGMIkA_ zBtxMxzqDxbekKJ85JSPq*Hf>E8K~$b5Hq|4>Dm04DWAo~fRTZrf#EI-XNUbo7U?T2 z(id2yZ-{6%_}<_apTTj3TXBKT6>j|x42-Paj2mhWcw8~}J&|+8JQ^Z$gWu}{zt`k! ec0X1=&kKB>oA_UN`7F#B#I<}wgLbFFkvJB delta 315 zcmaDQ^i7a&IWI340}%A^ZcIJRK9TPTZonpiDM9#aZOFhdGwEo%)+3RgBONNtg53isp( zjLO11wXAubKyhBUI3HYG4=B!`4K}(+EJXk)uE3KbSOpZQWy}*w5dsP*iPW$bvDPrA z2v_lfglias88k&EuVd0yVg^~m0VG}mF~ducBdZJ}^Gg--Qd3hDlJZM3CVyd4U~%&G t)Z47XoX^6@I(ZJe0RUiMMe_gv diff --git a/__pycache__/chatgpt_values.cpython-311.pyc b/__pycache__/chatgpt_values.cpython-311.pyc index d8172a87541249f89a4dcd8b5dbfccc5a140b709..9014cf7cf85f3ceec49817dad46cb3c62e76be1d 100644 GIT binary patch delta 111 zcmdlayIGcZIWI340}z=0+nTy;BJWbhJsUSGGcj^azQ&|AnTgqL@&}HT$@Z+QlQ%G% wPtIcvm~76X4iejZkcE+hF=z8(o>Ppfv5dkj4g4SKnD`j=J}_VsMJhlW0IL2VPXGV_ delta 193 zcmdliyGfRJIWI340}!-xu1#Gsk#{NM?v0z3nI>On(qd9jn9RuRHu(~>sFaa`4i_h< zQb}rYNqlKuW{HxOQf_X3j((2PWJVT?$?KUd@GFTW!j#R&SpKpzW^X>ibBa+lhEbTM Uf&W7d6Cb1A2L?={NCoI-05<0~egFUf diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc index 8e0dc90ca42fc502df64a750af1a9238eb1a3407..f83e895d320a2f32ec4228344672cb3f459c9dfc 100644 GIT binary patch delta 646 zcmeAd|0d42oR^o20SJVDY)uv5-N={4$oOn>C8KM75nl~s3X3F24h&M*5bQk06!uyc zpgadcEQJ-p2J1zZL)Xh%!;r#>q~5!RC51hk1!Pf?E>Mn3vL0e9kWAsuW(7+yr|{IW zOjR59C+@-Ngs7zL*WDK@92?))aB5v6?^?5=bhb>>}wDNuYHs zDN-;UKx3sLRshYBK@ydPh(aAH2h_z}#9E`tlp+sR&XA&j6jZE0gA}1MOu-DAN|Uvi zbwrtgVNe7Lzn9>^-~@4nH>WZ0VCB*PvK4^1c>QDzPB~W-+a2jwOxzCCTrml`AP_x) zbB6jA0i^{tR|E_$08vzQgXaw^=L4Qsto%;YT(OF|Ad)=6b4KPB5seixS47M%08vu% zNa^#vhaab6%GL*}RgWNE1jEsRM~$ X95%W6DWy57c160AKXJ`u0m%RWh=_&* delta 573 zcmew+-Y?F#oR^o20SH3AY)#$Gvym^0k#WuBN=DcET9z8d6gEka92lgqBG|R8H4G{2 z2!4?tP%R6BpTdD)7wG}jaw7OCT-mH31B;kbxNF(+1kq%9vKhg$^~@=}Kxw8FzFM{# zmKwHf7O*gD3V$tAia;%Mo_~s9EmNLP4Qq-JRF18NDMh%7mw^E&?f_(qK-pF`EGfJY zON-fn>P4XrU`-K&nxzR;A&#U1$gT%lC!Hcu%LJ5^glPd9D+MtYXpl6Ls0>6D>@=nn zS)eZFB37VkIjCxe6nR7#fMpb*GEBh?nu>l^Jehe4DY*)XDP@_-sZ}DAOPQqwKz=Ub z1QEg@f_d{&<{hkD>Oi&v5Er*kPUn=f6_A{venmiOfz1^Gg9gtVBC<0wuZU=@khvma z*5G@CU2HslD=NOky{>!S!b%R%Uf@4o)gWHYG@@#h* E0T2!w!2kdN delta 83 zcmbO#@Q0swIWI340}y=7T$kFpk#`3(TNon)!*qtpcUe>?e_+;TN@1L=%i_z(G&!F| lZ1O~wMcnK_)h~f+7>bxC+p(TwoHv=5O_A}zW(&5vi~z_R7Qp}j diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index b0cb594d0a313da699fb3af9aeaaa71766bffb0f..887e1c7a35fd31e69d65e5cd466c28019a61e7f7 100644 GIT binary patch delta 1879 zcmai!PfR0K9LGB|ZKrhJv=mCAfiAPK0oS$sEv4*sVfhbITm%)Bm29_fD3x}qZHX(+ z*el14Z%<}5o2U_QXcNVYXJeFfNTa=LI2sO~U4Na15FF{j5kzUL3;O)v_1)FrzgVa8PlI0q z=Nokqc!-H`*dTs|hnNWa4H5*x!YlGxOdevIWHY{L)B}n`@&TDNNDzn{$dp0+c|aVX zTLz+m(D2?4na2}4b;+!3#nZLdmHFEEfQRqM$|gKhV;LIzB?{AuQ+60GKFwve)+IZ< zgtY~zITE({^7Hz`I%Nx?|y=|s05j$JtPC8cgZPg_wMNuE3_u{)^Ql8$iK)>N#rGdm`amv-p9YE zR|8Oe->44tRWWSu`n9h-IipuR8>XvSf*jviqOGt>i z?_3!=e-Mi_SV`%eu#?`G@PN=*N@RuHt|+9U390@$0HZk}y0at3a#I#W@oe0}C{N$u&JW1!#T~ezl2^m>MEijTqP7d=~vNob*7?VIdrRHsr7WK zXbdb1Yu)=y9>TQsmAL*RRN}@iOq6AxDm!yUXRgdTi>{s$+xvK>#18$z2G7`_%7#j8 z=w$qiohh<2Wm|KxrMG0e^7u~CHUd}4HgX(SZ8xhk)izQNgb!_c&z5Q%u6agE?C|mG Y8C&?h=PUYhhM~L{rvJZZ@^Iw-19LOViU0rr delta 1050 zcmZva&rcIU6vt;~Tl#Bv+tSjeVnup@5K^UOV+dEf7QnK%1Bw=}6g(KIi? z^>+H@d?LN3f2S<0n!jk0D!IFge4#9wE6N)--O0VsQ*czJB?VH#XC#p9u}K<93`ws| zl1Ktb`fS3GxS$`SqZ(mA4!h=~JGcsa>ogkHQDL9Vx?9U>p`jy%vFgxZAWygh_S@=| z(2Y2f12#z`2_qS_NfL<<$w8YiBn<26T!Vg#2Dytj!J%07g0;o97?D5S!Oo#gR$`De zC@|sYy6ueDoWnBV$&@qP^@uF9RZ7S+{5BRP=m>BRj99%|xf4bU;*V)SCwi8{wbgJW`wqZJ)f zb&jcj9T7Ob#lql(eBe#{{|-CK13U;P<+`^!l-;zKf;FC%E8e*5^bOKe5_}n&ldHbW z?tFn&Cxky=T7>ZVPUi_s!x=aW=ivO3LxkaiXaTQK@HxUTBeQCk98v@HBJTR=C5+w9 zS;36$aso47RksgMa9Ol)3RmQ;5^ZDFrMxgFBD|&K=}q}tPtk(x@y9*4tZc7bM^?@BbZj6_pnd?=mWGvy z Date: Sun, 28 Jan 2024 17:03:03 +0800 Subject: [PATCH 139/164] bool --- streamlit_app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 19c67dd86ad4..e49ef709dfc2 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -98,8 +98,6 @@ full_output = "" for key, value in test_results.items(): dm = False - anaemia = False - LDLBP = False BMI = False print (f"looking at {key} and {value}") if value["test_found"]: From a794e09d6151e0d3ed7175954cd7771adab4b7a6 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 28 Jan 2024 17:30:40 +0800 Subject: [PATCH 140/164] uncomment --- __pycache__/image_loading.cpython-311.pyc | Bin 2069 -> 2053 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/__pycache__/image_loading.cpython-311.pyc b/__pycache__/image_loading.cpython-311.pyc index dc1595adb58961fd0906b7059715f8c9a11d0600..45a05b84189a2aee571ac6ac5852f4542910732e 100644 GIT binary patch delta 83 zcmbO#&?>;YoR^o20SMYgpelwUrpb1!=NK1H=4DgaY|8e45dd@06-WR8 delta 101 zcmZn_m@2@#oR^o20SHY0ZB6ai$h(7?Esc?ZVLHR)i!7>>KQQYGq%cZ? Date: Sun, 28 Jan 2024 17:32:42 +0800 Subject: [PATCH 141/164] Update anaemia.py --- anaemia.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/anaemia.py b/anaemia.py index 892e2dd24e26..5e089ead8210 100644 --- a/anaemia.py +++ b/anaemia.py @@ -28,25 +28,23 @@ def anaemia_analysis (hbdict): print ("in anaemia analysis") hblevel = hbdict["hb"]["test_value"] if hblevel < 7: - return "Your haemoglobin level is dangerously low. Please visit a doctor immediately." + return ":large_orange_circle: Your haemoglobin level is dangerously low. Please visit a doctor immediately." if hblevel < hbdict["hb"]["test_ref_min"]: if not hbdict["mcv"]["test_found"] or not hbdict["rbc_count"]["test_found"]: - return "You have anaemia, but there is not enough information to determine the cause. Visit a doctor if you have any concerns of blood loss." + return ":large_orange_circle: You lkely have anaemia, but there is not enough information to determine the cause. Visit a doctor if you have any concerns of blood loss." mcv = hbdict["mcv"]["test_value"] if mcv < hbdict["mcv"]["test_ref_min"]: #microcytic mentzer = mcv/ hbdict["rbc_count"]["test_value"] if mentzer > 13: - output_phrase = "you have anaemia, which could be due to iron deficiency. This can be caused by minor bleeding e.g. menstruation, or from the gastrointestinal tract. Visit your doctor for an assessment to rule out sources of bleeding. Consider taking iron supplements and foods rich in iron, such as green leafy vegetables, meat, especially red meat (beef, mutton, pork), seafood, and organs (kidney, liver)." + output_phrase = ":large_orange_circle: You likely have anaemia, which could be due to iron deficiency. This can be caused by minor bleeding e.g. menstruation, or from the gastrointestinal tract. Visit your doctor for an assessment to rule out sources of bleeding. Consider taking iron supplements and foods rich in iron, such as green leafy vegetables, meat, especially red meat (beef, mutton, pork), seafood, and organs (kidney, liver)." else : - output_phrase = "you have anaemia, which could be related to genetic conditions such as thalassaemia. Visit your doctor for an assessment." + output_phrase = ":large_orange_circle: You likely have anaemia, which could be related to genetic conditions such as thalassaemia. Visit your doctor for an assessment." elif mcv > hbdict["mcv"]["test_ref_max"]: # macrocytic - output_phrase = "you have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." + output_phrase = ":large_orange_circle: You likely have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." else: #normocytic - output_phrase = "you have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." + output_phrase = ":large_orange_circle: You likely have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." else: - output_phrase = "You don't have anaemia." + output_phrase = ":large_green_circle: You likely do not have anaemia." return output_phrase #print (f"here is result: {anaemia_analysis (testdict)}") - - From 1d64e7ae2df62b2fcaa878c61014899e3c16a63f Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:33:03 +0800 Subject: [PATCH 142/164] Update bmi.py --- bmi.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bmi.py b/bmi.py index 0a3f4e7e75c5..687e3b5220f4 100644 --- a/bmi.py +++ b/bmi.py @@ -19,14 +19,12 @@ def bmi_advice(test_results): print ("in bmi advice") output_string = "I didn't catch that" - if not test_results["weight"]["test_found"] or not test_results["height"]["test_found"]: - return "I need both your weight and height to calculate your BMI." weight = test_results["weight"]["test_value"] height = test_results["height"]["test_value"] if weight > 0 and height > 0: bmi = round(weight / pow(height,2), 2) else: - return"I need both your weight and height to calculate your BMI." + return "You need both weight and height to calculate BMI." weightloss = False if bmi >=27.5: output_string = "You are obese. Your BMI is " + str(bmi) From aa4527c61ff667f71dc842a78ad3e28c6a490645 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Sun, 28 Jan 2024 17:39:23 +0800 Subject: [PATCH 143/164] edit bool --- __pycache__/image_loading.cpython-311.pyc | Bin 2053 -> 2053 bytes streamlit_app.py | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/__pycache__/image_loading.cpython-311.pyc b/__pycache__/image_loading.cpython-311.pyc index 45a05b84189a2aee571ac6ac5852f4542910732e..c95732b5ad121f92d48cbf954e96051079bf3180 100644 GIT binary patch delta 19 ZcmZn_XcgdE&dbZi00gb_8@Yb70{|%M1YrOG delta 19 ZcmZn_XcgdE&dbZi00ix_8@Yb70{|%O1YrOG diff --git a/streamlit_app.py b/streamlit_app.py index e49ef709dfc2..4c8791c0aa77 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -96,9 +96,9 @@ print (test_attributes) #test_results test_attributes full_output = "" + dm = False + BMI = False for key, value in test_results.items(): - dm = False - BMI = False print (f"looking at {key} and {value}") if value["test_found"]: if key == "hb": @@ -110,6 +110,7 @@ print (f"LDL/BP {chol_output}") full_output += f"**LDL/BP** \n{chol_output} \n\n" elif key == "glucose" or key == "hba1c": + print (f"in DM and checking if entered before {dm}") if not dm: glucose_output = get_dm_advice(test_attributes, test_results) full_output += f"**Glucose** \n{glucose_output} \n\n" @@ -119,10 +120,11 @@ bp_output = "We need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90. \n\n" full_output += f"**BP** \n{bp_output}\n" elif key == "weight" or key == "height": + print (f"in BMI and checking if entered before {BMI}") if not BMI: bmi_output = bmi_advice(test_results) BMI = True - full_output += f"**BMI** \n{bmi_output} \n\n" + full_output += f"**BMI** \n{bmi_output} \n\n" print(full_output) if full_output == "": # if no supported lab results found full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in our About page." From eb4a69f5fa5ae03c0b4d0b86ec7c7b456a8ee494 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:40:01 +0800 Subject: [PATCH 144/164] Update diabetes.py --- diabetes.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/diabetes.py b/diabetes.py index 2381c6b34345..8a928718a838 100644 --- a/diabetes.py +++ b/diabetes.py @@ -34,10 +34,10 @@ def get_dm_advice(inputattributes, inputdict): output_phrase = "I didn't catch that." lifestyle = False #known dm - a1c_value = inputdict["hba1c"]["test_value"] if inputdict["hba1c"]["test_found"] else 0 - glucose_value = inputdict["glucose"]["test_value"] if inputdict["glucose"]["test_found"] else 0 + a1c_value = inputdict["hba1c"]["test_value"] + glucose_value = inputdict["glucose"]["test_value"] if inputattributes["diabetes"]: - if a1c_value >0: + if inputdict["hba1c"]["test_found"]: if inputattributes["age"] >= 80: a1ctarget = 8 elif inputattributes["age"] <=40: @@ -45,33 +45,33 @@ def get_dm_advice(inputattributes, inputdict): else: a1ctarget = 7.0 if a1c_value > a1ctarget: - output_phrase = "your HbA1c is above target, your diabetes can be controlled better. Aim for a HbA1c <7." + output_phrase = ":large_orange_circle: Your HbA1c is above target, your diabetes can be controlled better. Aim for a HbA1c below 7." lifestyle = True else: - output_phrase = "your HbA1c is within range for a diabetic, <7." - if glucose_value >0: + output_phrase = ":large_green_circle: Your HbA1c is below 7, which is within expected range for a diabetic." + else: if glucose_value > 6: - output_phrase += "\nYour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." + output_phrase += " \nYour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." else: - output_phrase += "\nYour fasting glucose level is within range, <6." + output_phrase += " \nYour fasting glucose level is within range, <6." else: #diagnose dm if a1c_value >= 6.5 or glucose_value >= 7: - output_phrase = "You have diabetes. Consult a doctor for advice, you may need to be started on medications." + output_phrase = ":large_orange_circle: You likely have diabetes. Consult a doctor for advice, you may need to be started on medications." lifestyle = True - elif a1c_value >= 6.1 or glucose_value >=6.1: - output_phrase = "You have prediabetes." + elif a1c_value >= 5.7 or glucose_value >=5.6: + output_phrase = ":large_yellow_circle: You likely have prediabetes." if a1c_value >= 5.7: - output_phrase += " Your HbA1c is >6.0." + output_phrase += " Your HbA1c is >5.7." if glucose_value >=5.6: - output_phrase += " Your fasting glucose is >6.0. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." + output_phrase += " Your fasting glucose is >5.6. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." lifestyle = True else: - output_phrase = "You do not have diabetes." + output_phrase = ":large_green_circle: You likely do not have diabetes." if lifestyle: output_phrase += " Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein, and half with fruit and vegetables). Maintain a healthy weight BMI ranging from 18.5 to 22.9 kg/m2. Exercise regularly, aiming for 150 minutes of moderate-intensity activity per week or 20 minutes of vigorous-intensity activity 3 or more days a week). Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if inputattributes["smoker"]: - output_phrase += " Quit smoking." + output_phrase += " You are highly encouraged to quit smoking." return output_phrase -#print(f"advice {get_dm_advice(test_attributes, testdict)}") \ No newline at end of file +#print(f"advice {get_dm_advice(test_attributes, testdict)}") From d550b79f5c7a4f2ab6034db6afb76281e84df82c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:40:16 +0800 Subject: [PATCH 145/164] Update bmi.py --- bmi.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bmi.py b/bmi.py index 687e3b5220f4..53687f503196 100644 --- a/bmi.py +++ b/bmi.py @@ -22,20 +22,20 @@ def bmi_advice(test_results): weight = test_results["weight"]["test_value"] height = test_results["height"]["test_value"] if weight > 0 and height > 0: - bmi = round(weight / pow(height,2), 2) + bmi = round(weight / pow(height,2), 1) else: - return "You need both weight and height to calculate BMI." + return ":large_yellow_circle: You need both weight and height to calculate BMI." weightloss = False if bmi >=27.5: - output_string = "You are obese. Your BMI is " + str(bmi) + output_string = ":large_orange_circle: You are obese. Your BMI is " + str(bmi) weightloss = True elif bmi >= 23: - output_string = "You are overweight. Your BMI is " + str(bmi) + output_string = ":large_orange_circle: You are overweight. Your BMI is " + str(bmi) weightloss = True elif bmi < 18.5: - output_string = "You are underweight. Your BMI is " + str(bmi)+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." + output_string = ":large_orange_circle: You are underweight. Your BMI is " + str(bmi)+ " Consider increasing food intake, for example, by taking smaller, frequent healthy meals. Increase protein intake by taking more lean meats, fish, eggs, dairy, legumes and nuts. Do strength training to build up muscles." else: - output_string = "You have a healthy BMI. Your BMI is " + str(bmi) + output_string = ":large_green_circle: You have a healthy BMI. Your BMI is " + str(bmi) if weightloss: output_string += "Choose healthier choices that are lower in fat (e.g. lean meat, low-fat dairy products), lower or no sugar (e.g. unsweetened beverages, fresh fruits), and higher in fibre (e.g. whole-meal bread, brown rice). Look out for alternatives that are lower in calories. Reduce your meal sizes by consuming ¾ of your usual. Do some moderate-intensity aerobic physical activities such as brisk walking, swimming or cycling for a minimum of 150-300 minutes weekly. If you're just starting out, accumulating shorter bouts of 10-minute exercise is a good start too." return output_string From 216f2ad18e462c666d52b1d4a20b8edcf372d247 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:40:32 +0800 Subject: [PATCH 146/164] Update lipids_ranges.py --- lipids_ranges.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 81366dc75526..cf3dcb154888 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -97,7 +97,7 @@ def getLDLBPtarget (attributes,testvals): if not all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): print ("something missing "+str((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]))) print(bool(bval), bool(attributes["age"]), bool (attributes["sex"]), bool(attributes["race"]), bool(testvals["total_cholesterol"]["test_value"]), bool(testvals ["hdl_cholesterol"]["test_value"])) - return "More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). We also need your HDL cholesterol and total cholesterol. In general, BP <140/90 and LDL <3.4 if no other risk factors." + return ":large_yellow_circle: More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). In general, aim for BP <140/90 and LDL <3.4 if you have no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; @@ -176,10 +176,12 @@ def getLDLBPtarget (attributes,testvals): sex = 0 if attributes["sex"].lower() == "male" else 1 age = attributes["age"] tcval = testvals ["total_cholesterol"]["test_value"] - if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": - tcval *= 0.02586 - testvals ["total_cholesterol"]["test_value"] *= 0.02586 - testvals ["total_cholesterol"]["test_unit"] = "mmol/L" + # if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + # if tcval > 280: cholbracket = 3 + # elif tcval > 240: cholbracket = 2 + # elif tcval > 200: cholbracket = 1 + # elif tcval > 160: cholbracket = 0 + # else: cholbracket = -1 if testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": if tcval > 7.2: cholbracket = 3 elif tcval > 6.1: cholbracket = 2 @@ -191,10 +193,11 @@ def getLDLBPtarget (attributes,testvals): return "invalid cholesterol units" hval = testvals ["hdl_cholesterol"]["test_value"] - if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": - hval *= 0.02586 - testvals ["hdl_cholesterol"]["test_value"] *= 0.02586 - testvals ["hdl_cholesterol"]["test_unit"] = "mmol/L" + # if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + # if hval > 59: hdlbracket = 0 + # elif hval > 49: hdlbracket = 1 + # elif hval > 40: hdlbracket = 2 + # else: hdlbracket = 3 if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": if hval > 1.5: hdlbracket = 0 elif hval > 1.2: hdlbracket = 1 @@ -238,7 +241,7 @@ def getLDLBPtarget (attributes,testvals): curdict = agedict[20] agebracket = 0 if age <35 else 1 else: - return "You are too young to use this calculator. In general, aim BP <140/90 and LDL < 3.4." + return ":large_yellow_circle: You are too young to use this calculator. In general, aim for BP <140/90 and LDL < 3.4." # age only points agescore += curdict["age"][agebracket][sex] @@ -262,7 +265,7 @@ def getLDLBPtarget (attributes,testvals): elif attributes["race"].lower() == "chinese": raceint = 2 else: - return "This calculator is not validated for other races. In general, aim LDL <3.4 and BP <140/90." + return ":large_yellow_circle: This calculator is not validated for other races. In general, aim for LDL <3.4 and BP <140/90." #matching to cardiovascular risk bracket cvriskdict = { @@ -285,18 +288,13 @@ def getLDLBPtarget (attributes,testvals): recmeds = False #print (f"score {score} LDL target {LDLtargetcalc}") - if not testvals ["ldl_cholesterol"]["test_found"]: - return "LDL cholesterol not found. LDL cholesterol is the main cholesterol that affects medical management." - if testvals ["ldl_cholesterol"]["test_unit"].lower() =="mg/dl": - testvals ["ldl_cholesterol"]["test_value"] *= 0.02586 - testvals ["ldl_cholesterol"]["test_unit"] = "mmol/L" if testvals ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: - output_phrase = "your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + output_phrase = ":large_orange_circle: Your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if recmeds: output_phrase += "You may require cholesterol lowering medications, consult your doctor. " else: - output_phrase = "Your LDL cholesterol is within target range, less than " + str(LDLtargetcalc) + output_phrase = ":large_green_circle: Your LDL cholesterol is within target range, less than " + str(LDLtargetcalc) + "." if testvals["systolic_bp"]["test_found"]: bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic_bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: @@ -307,9 +305,9 @@ def getLDLBPtarget (attributes,testvals): if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: - output_phrase += "Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) + output_phrase += ":large_green_circle: Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) if attributes["smoker"]: - output_phrase += "\nQuit smoking." + output_phrase += "\nYou are highly encouraged to quit smoking." return output_phrase #print (f"advice is {getLDLBPtarget (test_attributes, testdict)}") From 919ba681668f540fcf200dfb56b75ec1a5fde8db Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:22:24 +0800 Subject: [PATCH 147/164] add logo --- streamlit_app.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 4c8791c0aa77..da573f80ce3a 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -17,6 +17,7 @@ #from dotenv import load_dotenv #load_dotenv() +os.environ['API_KEY']='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' API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) @@ -40,8 +41,12 @@ """ with tab1: - st.title('LAB LOKUN') - st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately!') + col1, mid, col2 = st.columns([1,1,10]) + with col1: + st.image("https://i.ibb.co/869GgfZ/stethoscope-logo-text.jpg", width=100) + with col2: + st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately') + #st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately') # User inputs age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") @@ -96,21 +101,20 @@ print (test_attributes) #test_results test_attributes full_output = "" - dm = False - BMI = False for key, value in test_results.items(): + dm = False + anaemia = False + LDLBP = False + BMI = False print (f"looking at {key} and {value}") if value["test_found"]: if key == "hb": fbc_output = anaemia_analysis (test_results) - print (f"FBC {fbc_output}") full_output += f"**FBC** \n{fbc_output} \n\n" # streamlit needs 2 whitespace before newline char elif key == "ldl_cholesterol": chol_output = getLDLBPtarget (test_attributes, test_results) - print (f"LDL/BP {chol_output}") full_output += f"**LDL/BP** \n{chol_output} \n\n" elif key == "glucose" or key == "hba1c": - print (f"in DM and checking if entered before {dm}") if not dm: glucose_output = get_dm_advice(test_attributes, test_results) full_output += f"**Glucose** \n{glucose_output} \n\n" @@ -120,11 +124,10 @@ bp_output = "We need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90. \n\n" full_output += f"**BP** \n{bp_output}\n" elif key == "weight" or key == "height": - print (f"in BMI and checking if entered before {BMI}") if not BMI: bmi_output = bmi_advice(test_results) BMI = True - full_output += f"**BMI** \n{bmi_output} \n\n" + full_output += f"**BMI** \n{bmi_output} \n\n" print(full_output) if full_output == "": # if no supported lab results found full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in our About page." @@ -134,9 +137,13 @@ with tab2: - st.markdown("**Lab Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") - st.header('Lab measurements included for analysis') + col1, mid, col2 = st.columns([1,1,10]) + with col1: + st.image("https://i.ibb.co/869GgfZ/stethoscope-logo-text.jpg", width=100) + with col2: + st.markdown("**Lab Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") + st.subheader('Lab measurements included for analysis') st.markdown(measurements_list) - st.write('Other lab tests will be added soon...stay tuned!') + st.write('Other lab tests will be added soon...stay tuned!') st.caption('Disclaimer: Information provided through our app is for informational and educational purposes only and is not intended as a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.') From 6fd650929afc98479cd4bab08f65bf110ccd4ac7 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:54:02 +0800 Subject: [PATCH 148/164] Update streamlit_app.py --- streamlit_app.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index da573f80ce3a..233376f03206 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -16,8 +16,7 @@ from bmi import bmi_advice #from dotenv import load_dotenv -#load_dotenv() -os.environ['API_KEY']='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' + API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) From bfef83dff577d93884b369c24c2d98cefccc9f41 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:47:31 +0800 Subject: [PATCH 149/164] Update diabetes.py --- diabetes.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/diabetes.py b/diabetes.py index 8a928718a838..408cc95d5865 100644 --- a/diabetes.py +++ b/diabetes.py @@ -34,10 +34,10 @@ def get_dm_advice(inputattributes, inputdict): output_phrase = "I didn't catch that." lifestyle = False #known dm - a1c_value = inputdict["hba1c"]["test_value"] - glucose_value = inputdict["glucose"]["test_value"] + a1c_value = inputdict["hba1c"]["test_value"] if inputdict["hba1c"]["test_found"] else 0 + glucose_value = inputdict["glucose"]["test_value"] if inputdict["glucose"]["test_found"] else 0 if inputattributes["diabetes"]: - if inputdict["hba1c"]["test_found"]: + if a1c_value >0: if inputattributes["age"] >= 80: a1ctarget = 8 elif inputattributes["age"] <=40: @@ -49,7 +49,7 @@ def get_dm_advice(inputattributes, inputdict): lifestyle = True else: output_phrase = ":large_green_circle: Your HbA1c is below 7, which is within expected range for a diabetic." - else: + if glucose_value >0: if glucose_value > 6: output_phrase += " \nYour fasting glucose level is slightly high. Please consult your doctor for your specific glucose targets. Having a HbA1c measurement may be helpful to better evauate your diabetes control." else: @@ -59,12 +59,12 @@ def get_dm_advice(inputattributes, inputdict): if a1c_value >= 6.5 or glucose_value >= 7: output_phrase = ":large_orange_circle: You likely have diabetes. Consult a doctor for advice, you may need to be started on medications." lifestyle = True - elif a1c_value >= 5.7 or glucose_value >=5.6: + elif a1c_value >= 6.1 or glucose_value >=6.1: output_phrase = ":large_yellow_circle: You likely have prediabetes." if a1c_value >= 5.7: - output_phrase += " Your HbA1c is >5.7." + output_phrase += " Your HbA1c is >6.0." if glucose_value >=5.6: - output_phrase += " Your fasting glucose is >5.6. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." + output_phrase += " Your fasting glucose is >6.0. If this was a non-fasting sample, it may be difficult to assess. A fasting sample is preferred." lifestyle = True else: output_phrase = ":large_green_circle: You likely do not have diabetes." From dc2b2c488010a653bc4d1937daa60cb323a27ed6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:53:30 +0800 Subject: [PATCH 150/164] Update lipids_ranges.py --- lipids_ranges.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index cf3dcb154888..887641bbd685 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -97,7 +97,7 @@ def getLDLBPtarget (attributes,testvals): if not all ((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"])): print ("something missing "+str((bval, attributes["age"], attributes["sex"], attributes["race"], testvals["total_cholesterol"]["test_value"], testvals ["hdl_cholesterol"]["test_value"]))) print(bool(bval), bool(attributes["age"]), bool (attributes["sex"]), bool(attributes["race"]), bool(testvals["total_cholesterol"]["test_value"]), bool(testvals ["hdl_cholesterol"]["test_value"])) - return ":large_yellow_circle: More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). In general, aim for BP <140/90 and LDL <3.4 if you have no other risk factors." + return ":large_yellow_circle: More information is needed to calculate your blood pressure or cholesterol target. Please fill in the boxes above (age, sex, race, systolic blood pressure). We also need your HDL cholesterol and total cholesterol. In general, aim for BP <140/90 and LDL <3.4 if you have no other risk factors." #dictionary with the values (M, F), corresponding to lower bound of age e.g. 20-40 would be 20 # first sieve out all 20-40, then split into 20-34 and 35-39 for age score, and total chol for chol score # age as tuple (-9, -7,-4, -3): 20-34 M -9 F -7, 35-39 M -4 F -3 ; @@ -176,12 +176,10 @@ def getLDLBPtarget (attributes,testvals): sex = 0 if attributes["sex"].lower() == "male" else 1 age = attributes["age"] tcval = testvals ["total_cholesterol"]["test_value"] - # if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": - # if tcval > 280: cholbracket = 3 - # elif tcval > 240: cholbracket = 2 - # elif tcval > 200: cholbracket = 1 - # elif tcval > 160: cholbracket = 0 - # else: cholbracket = -1 + if testvals ["total_cholesterol"]["test_unit"].lower() =="mg/dl": + tcval *= 0.02586 + testvals ["total_cholesterol"]["test_value"] *= 0.02586 + testvals ["total_cholesterol"]["test_unit"] = "mmol/L" if testvals ["total_cholesterol"]["test_unit"].lower() =="mmol/l": if tcval > 7.2: cholbracket = 3 elif tcval > 6.1: cholbracket = 2 @@ -193,11 +191,10 @@ def getLDLBPtarget (attributes,testvals): return "invalid cholesterol units" hval = testvals ["hdl_cholesterol"]["test_value"] - # if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": - # if hval > 59: hdlbracket = 0 - # elif hval > 49: hdlbracket = 1 - # elif hval > 40: hdlbracket = 2 - # else: hdlbracket = 3 + if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mg/dl": + hval *= 0.02586 + testvals ["hdl_cholesterol"]["test_value"] *= 0.02586 + testvals ["hdl_cholesterol"]["test_unit"] = "mmol/L" if testvals ["hdl_cholesterol"]["test_unit"].lower() =="mmol/l": if hval > 1.5: hdlbracket = 0 elif hval > 1.2: hdlbracket = 1 @@ -241,7 +238,7 @@ def getLDLBPtarget (attributes,testvals): curdict = agedict[20] agebracket = 0 if age <35 else 1 else: - return ":large_yellow_circle: You are too young to use this calculator. In general, aim for BP <140/90 and LDL < 3.4." + return ":large_yellow_circle: You are too young to use this calculator. In general, aim for BP <140/90 and LDL cholesterol < 3.4." # age only points agescore += curdict["age"][agebracket][sex] @@ -265,7 +262,7 @@ def getLDLBPtarget (attributes,testvals): elif attributes["race"].lower() == "chinese": raceint = 2 else: - return ":large_yellow_circle: This calculator is not validated for other races. In general, aim for LDL <3.4 and BP <140/90." + return ":large_yellow_circle: This calculator is not validated for other races. In general, aim for LDL cholesterol <3.4 and BP <140/90." #matching to cardiovascular risk bracket cvriskdict = { @@ -288,8 +285,13 @@ def getLDLBPtarget (attributes,testvals): recmeds = False #print (f"score {score} LDL target {LDLtargetcalc}") + if not testvals ["ldl_cholesterol"]["test_found"]: + return ":large_yellow_circle: LDL cholesterol not found. LDL cholesterol is the main cholesterol that affects medical management." + if testvals ["ldl_cholesterol"]["test_unit"].lower() =="mg/dl": + testvals ["ldl_cholesterol"]["test_value"] *= 0.02586 + testvals ["ldl_cholesterol"]["test_unit"] = "mmol/L" if testvals ["ldl_cholesterol"]["test_value"] > LDLtargetcalc: - output_phrase = ":large_orange_circle: Your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." + output_phrase = ":large_orange_circle: Your LDL cholesterol is high. Eat a healthy balanced diet - using My Healthy Plates (filling a quarter of the plate with wholegrains, quarter with good sources of protein (fish, lean meat, tofu and other bean products, nuts), and half with fruit and vegetables. increase soluble fibre intake, avoid food with trans fat,replace saturated fat with polyunsaturated fats. Certain diets like ketogenic diet increase LDL-C levels. Aim for regular moderate-intensity physical activity for 150-300min a week. For people who are overweight or obese, weight reduction of 5–10% could be beneficial for improving lipid profile. Limit alcohol intake to 1 drink per day for females, and 2 drinks per day for males." if recmeds: output_phrase += "You may require cholesterol lowering medications, consult your doctor. " @@ -305,11 +307,9 @@ def getLDLBPtarget (attributes,testvals): if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: - output_phrase += ":large_green_circle: Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) + output_phrase += ":large_green_circle: Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) + "." if attributes["smoker"]: - output_phrase += "\nYou are highly encouraged to quit smoking." + output_phrase += " \nYou are highly encouraged to quit smoking." return output_phrase #print (f"advice is {getLDLBPtarget (test_attributes, testdict)}") - - From 6dab260bf6032ff6fba00fd7fe9f9aa00932c088 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:57:42 +0800 Subject: [PATCH 151/164] Update lipids_ranges.py --- lipids_ranges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 887641bbd685..a3ae2f74984f 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -296,7 +296,7 @@ def getLDLBPtarget (attributes,testvals): output_phrase += "You may require cholesterol lowering medications, consult your doctor. " else: - output_phrase = ":large_green_circle: Your LDL cholesterol is within target range, less than " + str(LDLtargetcalc) + "." + output_phrase = ":large_green_circle: Your LDL cholesterol is within target range (less than " + str(LDLtargetcalc) + ")." if testvals["systolic_bp"]["test_found"]: bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic_bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: @@ -307,7 +307,7 @@ def getLDLBPtarget (attributes,testvals): if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: - output_phrase += ":large_green_circle: Your BP is in the normal range, less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) + "." + output_phrase += ":large_green_circle: Your BP is in the normal range (less than "+ str(BP_target[0]) + "/" + str(BP_target[1]) + ")." if attributes["smoker"]: output_phrase += " \nYou are highly encouraged to quit smoking." return output_phrase From 047973d7bf4d8cb495df07b020ff303f6cd622f6 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:59:03 +0800 Subject: [PATCH 152/164] Update streamlit_app.py --- streamlit_app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 233376f03206..155b7470f53f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -16,7 +16,7 @@ from bmi import bmi_advice #from dotenv import load_dotenv - +#load_dotenv() API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) @@ -109,24 +109,24 @@ if value["test_found"]: if key == "hb": fbc_output = anaemia_analysis (test_results) - full_output += f"**FBC** \n{fbc_output} \n\n" # streamlit needs 2 whitespace before newline char + full_output += f"**Full Blood Count** \n{fbc_output} \n\n" # streamlit needs 2 whitespace before newline char elif key == "ldl_cholesterol": chol_output = getLDLBPtarget (test_attributes, test_results) - full_output += f"**LDL/BP** \n{chol_output} \n\n" + full_output += f"**Cholesterol and Blood Pressure** \n{chol_output} \n\n" elif key == "glucose" or key == "hba1c": if not dm: glucose_output = get_dm_advice(test_attributes, test_results) - full_output += f"**Glucose** \n{glucose_output} \n\n" + full_output += f"**Blood Sugar** \n{glucose_output} \n\n" dm = True elif key == "systolic_bp": if not test_results["hdl_cholesterol"]["test_found"]: bp_output = "We need your cholesterol levels to interpret the blood pressure targets better. In general, aim for a blood pressure <140/90. \n\n" - full_output += f"**BP** \n{bp_output}\n" + full_output += f"**Blood Pressure** \n{bp_output}\n" elif key == "weight" or key == "height": if not BMI: bmi_output = bmi_advice(test_results) BMI = True - full_output += f"**BMI** \n{bmi_output} \n\n" + full_output += f"**Height/Weight (BMI)** \n{bmi_output} \n\n" print(full_output) if full_output == "": # if no supported lab results found full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in our About page." From 8b5a99b28f4c416e96342a1f9e9bfab85214692c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:04:41 +0800 Subject: [PATCH 153/164] Update lipids_ranges.py --- lipids_ranges.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index a3ae2f74984f..895c8a0bbf88 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -301,9 +301,9 @@ def getLDLBPtarget (attributes,testvals): bp = (testvals["systolic_bp"]["test_value"], testvals["diastolic_bp"]["test_value"]) if bp[0] > BP_target[0] or bp[1] > BP_target[1]: if bp[0] > 180 or bp[1] > 120: - output_phrase += " \n Your blood pressure is dangerously high, SBP >180 or DBP >120. Visit a doctor for assessment.\n" + output_phrase += " \n:large_orange_circle: Your blood pressure is dangerously high, SBP >180 or DBP >120. Visit a doctor for assessment.\n" else: - output_phrase += "\n Your blood pressure is high. Your target should be " + str(BP_target[0]) + "/" + str(BP_target[1]) + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." + output_phrase += " \n:large_orange_circle: Your blood pressure is high. Your target should be " + str(BP_target[0]) + "/" + str(BP_target[1]) + " . Take a healthy diet (e.g., reducing salt intake and alcohol consumption), increase physical activity, lose weight if overweight or obese." if attributes["stroke"]: output_phrase += "Since you have had a stroke before, your blood pressure targets may need to be customised according to the type of stroke. Seek advice from your stroke doctor for specific blood pressure targets." else: From 3f9cc784630ecad202d7233ba24aa65a3376584a Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:38:32 +0800 Subject: [PATCH 154/164] Update streamlit_app.py --- streamlit_app.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index 155b7470f53f..ce9be6284c1f 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -44,8 +44,7 @@ with col1: st.image("https://i.ibb.co/869GgfZ/stethoscope-logo-text.jpg", width=100) with col2: - st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately') - #st.subheader('Answer the questions, take a picture of your lab test results, and get your personal report immediately') + st.subheader('Instructions: \n1. Fill in the form below \n 2. Upload a picture of your lab test results \n3. Click "Generate my report!" button') # User inputs age = st.number_input("Enter your age", min_value=0, max_value=140, step=1,value="min") @@ -61,7 +60,7 @@ image = load_image() - if st.button('Analyse my results'): + if st.button('Generate my report!'): # Save test attributes test_attributes["age"] = age test_attributes["sex"] = sex @@ -90,21 +89,16 @@ st.text(response.usage) status.update(label="Analysed results!", state="complete", expanded=False) st.success(f"Extracted values in {extract_time} seconds.") # Use status instead of toast/success - for test_name, test_info in test_results.items(): - if test_info["test_found"]: - st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") - st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") - st.text("") # Insert YT logic print (test_results) print (test_attributes) #test_results test_attributes - full_output = "" + full_output = "" + dm = False + anaemia = False + LDLBP = False + BMI = False for key, value in test_results.items(): - dm = False - anaemia = False - LDLBP = False - BMI = False print (f"looking at {key} and {value}") if value["test_found"]: if key == "hb": @@ -126,13 +120,21 @@ if not BMI: bmi_output = bmi_advice(test_results) BMI = True - full_output += f"**Height/Weight (BMI)** \n{bmi_output} \n\n" + full_output += f"**Height/Weight (BMI)** \n{bmi_output} \n\n" print(full_output) if full_output == "": # if no supported lab results found - full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in our About page." + full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in the About page." st.error(f"{full_output}",icon="🚨") else: + st.subheader('REPORT') st.markdown(full_output) + # print test results + st.subheader('Measurement values detected') + for test_name, test_info in test_results.items(): + if test_info["test_found"]: + st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") + st.markdown(f"**Test Value:** {test_info['test_value']} {test_info['test_unit']}") + st.text("") with tab2: @@ -140,7 +142,8 @@ with col1: st.image("https://i.ibb.co/869GgfZ/stethoscope-logo-text.jpg", width=100) with col2: - st.markdown("**Lab Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times.") + st.text("") + st.markdown("**Lab Lokun** is an AI-assisted app that interprets and explains blood and lab test reports to provide personalised health advice and recommendations using Singapore ACG guidelines. **Lab Lokun** is co-created by doctors and non-doctors who have interpreted indecipherable lab results to their friends and family too many times. :joy:") st.subheader('Lab measurements included for analysis') st.markdown(measurements_list) st.write('Other lab tests will be added soon...stay tuned!') From 2c87d969ed137261aff03cd18d9c518903f69510 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:45:44 +0800 Subject: [PATCH 155/164] Update streamlit_app.py --- streamlit_app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamlit_app.py b/streamlit_app.py index ce9be6284c1f..05045c8d7d28 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -126,10 +126,10 @@ full_output = "No supported medical lab results detected in your image. \nCheck if your image contains lab results listed in the About page." st.error(f"{full_output}",icon="🚨") else: - st.subheader('REPORT') + st.subheader(':bookmark_tabs: Your Report') st.markdown(full_output) # print test results - st.subheader('Measurement values detected') + st.subheader(':test_tube: Measurement values detected') for test_name, test_info in test_results.items(): if test_info["test_found"]: st.markdown(f"**Test Name:** {test_name.replace('_', ' ').upper()}") From 0ba5661defd06ca1878155f3b26c4db07f2ddbf3 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:53:06 +0800 Subject: [PATCH 156/164] Update lipids_ranges.py --- lipids_ranges.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lipids_ranges.py b/lipids_ranges.py index 895c8a0bbf88..d0eedfee55d4 100644 --- a/lipids_ranges.py +++ b/lipids_ranges.py @@ -16,21 +16,21 @@ "ldl_cholesterol": { "test_found":True, "test_value":5.8, - "test_unit":"mmol/l", + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, "hdl_cholesterol": { "test_found":True, "test_value":1.0, - "test_unit":"mmol/l", + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, "total_cholesterol": { "test_found":True, "test_value":4.1, - "test_unit":"mmol/l", + "test_unit":False, "test_ref_min":False, "test_ref_max":False }, From 71ad3aec210139a52fef40039761494f8ecc8305 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Tue, 30 Jan 2024 20:53:21 +0800 Subject: [PATCH 157/164] anaemia edit --- __pycache__/anaemia.cpython-311.pyc | Bin 2523 -> 2718 bytes __pycache__/bmi.cpython-311.pyc | Bin 2410 -> 2424 bytes __pycache__/diabetes.cpython-311.pyc | Bin 3062 -> 3152 bytes __pycache__/image_loading.cpython-311.pyc | Bin 2053 -> 2053 bytes __pycache__/lipids_ranges.cpython-311.pyc | Bin 10573 -> 9880 bytes anaemia.py | 6 ++++-- image_loading.py | 2 +- streamlit_app.py | 6 +++--- testing.py | 18 +++++++++--------- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/__pycache__/anaemia.cpython-311.pyc b/__pycache__/anaemia.cpython-311.pyc index 481fd3d4a114ecc7f463f0f97e22d61d5be5b572..b6b64a007e8ab0ce706113ba0900c2e997a76483 100644 GIT binary patch delta 388 zcmcaDJWrHwIWI340}z~7*p^z$wUMutNj%vqC$T6!H9o&6F%L*3XBH*rq*^IVp2C!* zumHPUWPYhaPIhWe<>X&X?J7$c85r=W%LFSFWR=^zj5(cAaT*ayYgAH+GgEZ)N>)Qg z#py(tDLVNxTe6x7RAqWmYHA+buVDXx-Kmh0uaK8NIiCG9OWp;}yvbo4D)PBZE8I3% zU(vBYz;i{%_X7hXb1u^dCI)UG$p9oL&*X67u4ZfSZSeiT!XTPE`2~lpa5Za#ZG$b4 RFOtgyVm%P@m@L707yu%^hMfQa delta 189 zcmbOydRv%pIWI340}wRxY)sw9xsk7xiP3lRDyAfsmdO0l$vVvK?Cp#U43$83Evww- zugvL;ER_&m4Z85w!!*}j{O0iD>}X(7#NuYnLaQva05vOAUQdP(}g>Zt--g!_X7)qXu#yvoU+1k XtPQpewm`l}027GyKuCM?ZO+30@=Q5$ diff --git a/__pycache__/bmi.cpython-311.pyc b/__pycache__/bmi.cpython-311.pyc index 6b4afddfa7ede276c74fa6f5cc37273688d167e1..b9fd90b5fd842871ce041dfc6a9eafc80d9b7117 100644 GIT binary patch delta 534 zcmaDQ^h1buIWI340}ybfZ%ehF$a|D=*2K$>Y_&`^3@NM=|A`6JGS@Jruw}D=)D&sd zFsHChu47cyWM9U_z_1#KA)tzzfgyzhRjigJk12(7^BG27Mq6f(ZVn*v5~ThmNZ(6F zAW`LRm6KSMo*G}7nv;`X9-o|9l$?`lr4X54s*snOnxc@DUy?ET3zLGnldq?qTRKQL zLxZ(Ll@U~5eo6-0%)@^5Elzgp2IFV`2o9cJ%7Xn{)iibVhvt5*tt4FnyMPAZb_v-5%#^|w%mCyuOM;Yv zK??h1E=Fltc7#YRa}84pM>Y#cx=5pjIfY}g6Qimo=Q1V+hSfj}0ae@#3@K=0wJdo+ z8#Yg1=L-3VEriDGEvXB^e5p`K3jZZ!syTfEWr+zMgtT%s@piL598r z>2XU3F&P@H9jc@!D>5rhj$+nkRGd7Q`9Gt|=1nX-%)a74X<;BPHedv*W4O!0*yJ%e}pXn diff --git a/__pycache__/diabetes.cpython-311.pyc b/__pycache__/diabetes.cpython-311.pyc index f83e895d320a2f32ec4228344672cb3f459c9dfc..fa521adae0376fafec4fbecaea1c60db21607378 100644 GIT binary patch delta 1099 zcmZ`#O-~b16rGRG&~_LZq!emfxUk?OkVZ5>LXhA>l*Er15F{p;VczR>(xHWE3v|-4 z`~#cJrtUPxsELWXaqSO~q>wJU6WzJ18yBv8Go4s8dXsr`?>*<8d+z(uSL+vFieiu= z5mZ0m@_R8&({Jn|eXVTyN;Kjl4&(;n+PTG*DAduejoXClYuCu%&W!}&2HG_Wra4E@ zV3A<)neM;P&NS_!WfqA9X3#l{FZoJ*+UK@8)MYV9ve?WW)NL`DnNw3aE- zjkdb3H3r4VE!JhnJvM~~+Hc?@gC4@HP~&jh?9?)Vwn0XFnu5)cU0|bF4A9y^~z&LY;mMs`?W9#aa z0$L6{`Xub9G$rM9_O*P9SiuK7Sjl4q?i5I74Uhq8@)pi(O5z(&{FomBf*X!pQqJYI zj0&o5r+shPO8|D1n;Aa%pVMpsbS;hbqJ59MUq1TeM0in6x)EM9FMAh@SSQ>3;oZ9k zDR~dWj)7a2a4unn!1eNbwT0=#Y{Goh>b4yglxz+=ixPY$0n16dkKcspe?Arw^yWP; z@(fHkS|A%3Qkt65i-0oHsR-Z9*y2Dw$bA%rUHbs=8W>%v5nk^<|r{WY+#*<`4p zHKrmqVo(WG0;gbA#EN*@6|3%^bV02P8dAJTQNx)1PEp;Mbx|o^8(KS-)|{frQ=Pq4 z_C$!*glN@zN1qH%)dr`CZhW1w4}(D8wVwsA&@1-m;FxfoZuom^k)>n*lHDy##+-#- cQ^pwi86)KQ>7U=uqJoYWj7fV#c;a)AU!$)nF#rGn delta 979 zcmZ9IOK1~O6o%)WS0@jfw24WZ+bnET($HdQOH4~e6oV*A3u>!inn}`-Hql9=CQNMI zh`1WKo46~8s2d-M;7Yo5p)f6jjJtLtbXPZ}bmf`JXo813cg{WEdHnY({=;7W70=rV zu3e zMz9naeULZ;%pO>8O@&=>6j=k%LRW(;c?{g9pxC5Npp@Wha1tYNW;0fBHz>i=pn;rd zP!juZj0gN~GmDcb!CU7EqCu5r!S~hqm~lveE@x|eg@b|~Qwl5enr)+y;m2>OVEW`= z1`UF(W>698i1xLjrks9|LyIhAhs|t4Kpk(QlL3=Zb3`m-1PZD~l+NghF~LyH?1= z5ESfl(5C(cN7*ob!fcYG;7u?KH_KK0n7y%{Gt56*_dx_Lr|)OcT`}A0kgde?-@obB zGh6o}Na&b5GZ7z+=Ue4~AGL5UU0ExX@+iMj&6F!yU7(SOQaJ=VL2kMN3QOhEh>?m{ zxfBzC&M$s&6zxRU@S%0jJ_M2xe3f^2&(?o?eEM@<9lx+8spIpCdr`JE2UT}uGpV{q z6<7<48!0VuZY!lGu6&i$#4W{}kyFir>K%F=QoR!jtfkDxWzEtf*Hug8fC#fwn!_un zpCz9r@w9#Bj)rP7uZ56olWn``D)8qwaUsQpG3HpNo diff --git a/__pycache__/image_loading.cpython-311.pyc b/__pycache__/image_loading.cpython-311.pyc index c95732b5ad121f92d48cbf954e96051079bf3180..35c7f65f86b9d3cfd38e79db6b8cc98493b35fef 100644 GIT binary patch delta 19 ZcmZn_XcgdE&dbZi00f%p8@Yb70{|#01Wf<{ delta 19 ZcmZn_XcgdE&dbZi00gb_8@Yb70{|%M1YrOG diff --git a/__pycache__/lipids_ranges.cpython-311.pyc b/__pycache__/lipids_ranges.cpython-311.pyc index 887e1c7a35fd31e69d65e5cd466c28019a61e7f7..0d9439c9f43cc89dc25f6f2a841df4d2f29ff05a 100644 GIT binary patch delta 1617 zcmZ{i?@wD*7{|{!x7{smZ-3ZdD^R>+3QQ=1Wn&_a6?8yX6v2t8V^q$i)V8;91qpDk z?1e9g@de3wvqV{zn9QheW|}SWg@1uFX=h1zp)MK|6JKae&=-4Qd~Ufb$hMo@=brm{ zzTfXT_niCP*p(5-XM$iwa9NYLq@N>SIex{Y)}G(RVa$y!a_k1Tn!n0@O)fO6R@#v^ z=~9KGotjN<1oBLkM1TZ=bX7?hhzrQcDj`64dJ3vZue6(;<)uJ_YNw|UXavZy(`VVJ zrEWc<3E=32syhVQJ&sfp?Ww9eHHRDm@?4cffOvuQR!JC$4aoCVLVys+bEpD6Wl*=u zt4HXWp#FiCOBI5M{cdqL_w6%<(6Edt(VVKI>I_w!XIW!SbUmu_AEPaD9V7H5+;*$l=!+UB&jLAT5Dz4rJCrb(M(mdw z&-%~-&Cnsu@ZnkHE=Y|XaKsKd&OhL&14sOTBmRGfpN>3WA@n8op*7;Xzu5uRrMl_M z?6$SlGrDhA+!a2`u3AH^+186+Vbm7IW9+&u`t*33=sN^IUqti3@x3~Z=mq*3ouIGN z$xlq0m%gF-s8!?OIK1>tHfle?`s^9ATVh|2jHxhIKeYLe}VZL07JJJDT>eis->@(ifI9I{tBVVxIlv z{Gt}a57(1PC`swkij>LZmM_hul$ngwBeIWNTb^NAOiHq(BrvKlh zyTsJ2xRP5E=MwKp`3?7J!gf4A2C|O`yXEcS_RKwj#YbqK^7U6VY2V%YrENGkLzhz$ zGOX|Z!bJ8>@M!+FzfAmbLy=S@Nv;Z@-_6~_?Vs)jiNEjRlE3R(#a8PitUsYh;#?{@ zmst@dc_z1{B$5&p7jxo5{&@Wswynb{4Z{8I#hU!Lp)rgn@(qs$so%g;21cYzRBNb5khs4Oi3> z-&RIebDXd{P5&gPwx?$bG+U5!B|2Z6UMNj36hjMz#pPmXd3#l>qzvin7$z~Yt7o3q zGuLojf72iE)=;TJoNSEj@b1l)5?@zF*gS-HEWSc;uxJ@%?v}QCeRn=b%4K*c??bs~ c>CNWoQbszXe847KzCSk4;b0j(yjE=g0id&{EC2ui delta 2238 zcmah}O-vg{6y9Bf*Lc?k{}KWwn~*>Pm|w>j;y{2TK!GL!TJl3k4YLLpd)?ZGBy=|% za^X~=&LygvDpDhb=0s(+B2raVJw;Vg?b1!+LtC{~mEJ0(Ry|a$(&xpoU8hp4^?2rc z@B7~OW@de3^x>HKj>%*s;Pb%w883N0G5Z z&(Gd5{YCOAi0Bv4-ti&4le zkcg5>MRQigrK$AivP5$QrVSqQIQAP{DWY+jx#1vuOA@-Y9Y5XC;1e0{e}<0_LzK6pRW)TRkn!oh@4S2q^g5n><`7n7mu+qjoJ9N9LMQ zc&@LuqLX>&{hnogBoYlbkKmsz-;?9`v9$}^ZJp$KjBI`QuI-1F<=M1Gz6&9m;DXUb z0X1=jp-`Ml%=26%5EA}FNz4ZlTp$?aXA^NQ!lTeE^biRMfjK_H3yG%1FW_HWYq?M{ zdC&ekMRwq?$~!*#yPP8Hv2}NY&TKrBytw-&$y|do8Gvtm#F#9u8Y9V2@~mr+q(ep9 z1Yr;1JJr7iQjAS@98{S@>kTU7eZu&+7{9`Ft4#Noir5Si9^z zq_Xwvewp>bqq4ru0fp_~St+b9)z!B;n8`V!upOX|@g8ZXO0CM&turd)dBSvUFn0r zp-R%heMjnlw9U)5dHm1b6ilPCEsB5I_vs3_c4)O(l{vgkkj0B+sx%>&CQ@{%Y}u#M zHMfRUy5$M&-J-n;?Ne#rX2%xYC)0f?Lz!%?Q4RZVP05BfcvM5%#++g}y0cOYZ7Gj` z)sV@#pcq0qLoWmP6RkdT}qlroREU!!i)rp|8E4XR`&YDT3 zt8a)Z-MCE{i!YP-Sd+Xueg8`F^$+r 13: output_phrase = ":large_orange_circle: You likely have anaemia, which could be due to iron deficiency. This can be caused by minor bleeding e.g. menstruation, or from the gastrointestinal tract. Visit your doctor for an assessment to rule out sources of bleeding. Consider taking iron supplements and foods rich in iron, such as green leafy vegetables, meat, especially red meat (beef, mutton, pork), seafood, and organs (kidney, liver)." diff --git a/image_loading.py b/image_loading.py index 77f9af31a4e7..b43fdabc1d0c 100644 --- a/image_loading.py +++ b/image_loading.py @@ -25,7 +25,7 @@ def remove_nric(text): def extract_text(image,ocr_model): ocr_start_time = time.time() result = ocr_model.ocr(image) - result = result[0] #idk why this needs a result[0] instead of result for Github + result = result #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] diff --git a/streamlit_app.py b/streamlit_app.py index da573f80ce3a..59edaffe3f30 100644 --- a/streamlit_app.py +++ b/streamlit_app.py @@ -14,10 +14,10 @@ from diabetes import get_dm_advice from anaemia import anaemia_analysis from bmi import bmi_advice -#from dotenv import load_dotenv +from dotenv import load_dotenv -#load_dotenv() -os.environ['API_KEY']='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' +load_dotenv() +#os.environ['API_KEY']='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' API_KEY = os.environ['API_KEY'] # API_KEY in streamlit secret client = OpenAI(api_key=API_KEY) diff --git a/testing.py b/testing.py index fb46b95d5fe6..1ab9e3c3c981 100644 --- a/testing.py +++ b/testing.py @@ -18,18 +18,18 @@ } test_results = { - 'ldl_cholesterol': {'test_found': True, 'test_value': 2.2, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, - 'hdl_cholesterol': {'test_found': True, 'test_value': 1, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, - 'total_cholesterol': {'test_found': True, 'test_value': 3.7, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, - 'mcv': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, - 'hb': {'test_found': False, 'test_value': False, 'test_unit': 'g/dL', 'test_ref_min': False, 'test_ref_max': False}, - 'rbc_count': {'test_found': False, 'test_value': False, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, + 'ldl_cholesterol': {'test_found': False, 'test_value': 2.2, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'hdl_cholesterol': {'test_found': False, 'test_value': 1, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'total_cholesterol': {'test_found': False, 'test_value': 3.7, 'test_unit': 'mmol/l', 'test_ref_min': False, 'test_ref_max': False}, + 'mcv': {'test_found': True, 'test_value': 100, 'test_unit': False, 'test_ref_min': 85, 'test_ref_max': 90}, + 'hb': {'test_found': True, 'test_value': 10, 'test_unit': 'g/dL', 'test_ref_min': 11.5, 'test_ref_max': 15.5}, + 'rbc_count': {'test_found': True, 'test_value': 4.2, 'test_unit': False, 'test_ref_min': False, 'test_ref_max': False}, 'glucose': {'test_found': False, 'test_value': False, 'test_unit': 'mmol/L', 'test_ref_min': False, 'test_ref_max': False}, - 'hba1c': {'test_found': True, 'test_value': 6.0, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, + 'hba1c': {'test_found': False, 'test_value': 6.0, 'test_unit': '%', 'test_ref_min': False, 'test_ref_max': False}, 'systolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, 'diastolic_bp': {'test_found': False, 'test_value': False, 'test_unit': 'mmHg', 'test_ref_min': False, 'test_ref_max': False}, - 'height': {'test_found': True, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, - 'weight': {'test_found': True, 'test_value': 58, 'test_unit': 'kg', 'test_ref_min': False, 'test_ref_max': False} + 'height': {'test_found': False, 'test_value': 1.61, 'test_unit': 'm', 'test_ref_min': False, 'test_ref_max': False}, + 'weight': {'test_found': False, 'test_value': 58, 'test_unit': 'kg', 'test_ref_min': False, 'test_ref_max': False} } for key, value in test_results.items(): From 2abda39a756ea72a5f76d86a375be1b41347195e Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Tue, 30 Jan 2024 20:57:04 +0800 Subject: [PATCH 158/164] uncomment --- image_loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_loading.py b/image_loading.py index b43fdabc1d0c..b957cfc2c03c 100644 --- a/image_loading.py +++ b/image_loading.py @@ -25,7 +25,7 @@ def remove_nric(text): def extract_text(image,ocr_model): ocr_start_time = time.time() result = ocr_model.ocr(image) - result = result #idk why this needs a result[0] instead of result for Github + result = result [0] #idk why this needs a result[0] instead of result for Github extracted_text = '' for idx in range(len(result)): txt = result[idx][1][0] From a3ed01eb050e0537f7327fcb00bfe2f569ba6329 Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Tue, 30 Jan 2024 21:02:37 +0800 Subject: [PATCH 159/164] test --- anaemia.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/anaemia.py b/anaemia.py index 89613462797c..dbe5929ed1d4 100644 --- a/anaemia.py +++ b/anaemia.py @@ -44,7 +44,8 @@ def anaemia_analysis (hbdict): elif mcv > hbdict["mcv"]["test_ref_max"]: # macrocytic output_phrase = ":large_orange_circle: You likely have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." else: #normocytic - output_phrase = ":large_orange_circle: You likely have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." + output_phrase = ":large_orange_circle: You likely have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." + #output_phrase = ":large_orange_circle: You likely have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." else: output_phrase = ":large_green_circle: You likely do not have anaemia." return output_phrase From f5ff9f038d993f8c5c73619b66f8f870f431349e Mon Sep 17 00:00:00 2001 From: cobaltB12 Date: Tue, 30 Jan 2024 21:04:27 +0800 Subject: [PATCH 160/164] end test --- anaemia.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/anaemia.py b/anaemia.py index dbe5929ed1d4..89613462797c 100644 --- a/anaemia.py +++ b/anaemia.py @@ -44,8 +44,7 @@ def anaemia_analysis (hbdict): elif mcv > hbdict["mcv"]["test_ref_max"]: # macrocytic output_phrase = ":large_orange_circle: You likely have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." else: #normocytic - output_phrase = ":large_orange_circle: You likely have anaemia, which may be caused by low folate (vitamin B9) or vitamin B12 levels. Other causes may include chronic alcohol intake, thyroid problems, and liver problems. Consider taking more foods high in folate, such as broccoli, spinach, and brown rice, and foods high in vitamin B12, such as meat, milk, cheese and eggs." - #output_phrase = ":large_orange_circle: You likely have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." + output_phrase = ":large_orange_circle: You likely have anaemia, which may be associated with chronic illness such as kidney disease, or chronic inflammatory conditions." else: output_phrase = ":large_green_circle: You likely do not have anaemia." return output_phrase From 759a991248b5bfbbc8a75e72893dc9bf16dc8dee Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:41:55 +0800 Subject: [PATCH 161/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index 92efcf837cb8..d8ec945c2c8c 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -109,7 +109,7 @@ def extract_values(client,extracted_text): extract_start_time = time.time() extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( - model="gpt-3.5-turbo-1106", + model="gpt-4-turbo-preview", #gpt-3.5-turbo-1106 response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, From 9e04a8ce5540401a48f38c00da8082ea2993b32c Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:43:37 +0800 Subject: [PATCH 162/164] Update chatgpt_values.py --- chatgpt_values.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chatgpt_values.py b/chatgpt_values.py index d8ec945c2c8c..e0f04ba4c75b 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -110,6 +110,7 @@ def extract_values(client,extracted_text): extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( model="gpt-4-turbo-preview", #gpt-3.5-turbo-1106 + seed=04022024 response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, From b45cf6c414a15e844f49940016c53a6c626e9ba5 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:43:56 +0800 Subject: [PATCH 163/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index e0f04ba4c75b..d3dc82fdf327 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -110,7 +110,7 @@ def extract_values(client,extracted_text): extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( model="gpt-4-turbo-preview", #gpt-3.5-turbo-1106 - seed=04022024 + seed=04022024, response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, From 03ef658361558d85271fbca38a6af35c3a541331 Mon Sep 17 00:00:00 2001 From: loonyx8 <66733801+loonyx8@users.noreply.github.com> Date: Sun, 25 Feb 2024 11:04:48 +0800 Subject: [PATCH 164/164] Update chatgpt_values.py --- chatgpt_values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatgpt_values.py b/chatgpt_values.py index d3dc82fdf327..f6a490df3cf4 100644 --- a/chatgpt_values.py +++ b/chatgpt_values.py @@ -110,7 +110,7 @@ def extract_values(client,extracted_text): extract_prompt = f"{template_prompt} {extracted_text}" response = client.chat.completions.create( model="gpt-4-turbo-preview", #gpt-3.5-turbo-1106 - seed=04022024, + seed=4022024, response_format={ "type": "json_object" }, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."},