Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tongtong rbc #179

Open
wants to merge 171 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
3a3a9a3
Update streamlit_app.py
loonyx8 Jan 11, 2024
e2ff554
Update streamlit_app.py
loonyx8 Jan 11, 2024
010ec2b
Update streamlit_app.py
loonyx8 Jan 11, 2024
000ad40
Update requirements.txt
loonyx8 Jan 11, 2024
515d85d
Update streamlit_app.py
loonyx8 Jan 11, 2024
f25775e
Update requirements.txt
loonyx8 Jan 11, 2024
21e04bc
Update requirements.txt
loonyx8 Jan 11, 2024
09c1a87
Update requirements.txt
loonyx8 Jan 11, 2024
e98a211
Update streamlit_app.py
loonyx8 Jan 11, 2024
f3cc66d
Update streamlit_app.py
loonyx8 Jan 11, 2024
788906d
Update requirements.txt
loonyx8 Jan 11, 2024
0b90d11
Update streamlit_app.py
loonyx8 Jan 11, 2024
5e373c6
Update streamlit_app.py
loonyx8 Jan 11, 2024
f99c286
Update requirements.txt
loonyx8 Jan 11, 2024
ffcb837
Update streamlit_app.py
loonyx8 Jan 11, 2024
98312a8
Update streamlit_app.py
loonyx8 Jan 11, 2024
aeda74d
Update streamlit_app.py
loonyx8 Jan 11, 2024
e20ed68
Update requirements.txt
loonyx8 Jan 11, 2024
0a4f96f
Update streamlit_app.py
loonyx8 Jan 11, 2024
12055b2
Update streamlit_app.py
loonyx8 Jan 11, 2024
b5156b0
Update requirements.txt
loonyx8 Jan 11, 2024
583b7e3
Update streamlit_app.py
loonyx8 Jan 11, 2024
f072235
Update requirements.txt
loonyx8 Jan 12, 2024
55e16f4
Update streamlit_app.py
loonyx8 Jan 12, 2024
b7dcdc5
Update streamlit_app.py
loonyx8 Jan 12, 2024
0e1ee92
Update streamlit_app.py
loonyx8 Jan 12, 2024
2ef4e98
Update streamlit_app.py
loonyx8 Jan 12, 2024
940f006
Create packages.txt
loonyx8 Jan 12, 2024
48876ec
Update streamlit_app.py
loonyx8 Jan 12, 2024
7e59c8b
Update streamlit_app.py
loonyx8 Jan 12, 2024
fbfe353
Update streamlit_app.py
loonyx8 Jan 12, 2024
bdbf4ea
Update streamlit_app.py
loonyx8 Jan 12, 2024
f2c6a6d
Update streamlit_app.py
loonyx8 Jan 12, 2024
c9d5d7d
Update streamlit_app.py
loonyx8 Jan 12, 2024
c3b2411
Update streamlit_app.py
loonyx8 Jan 12, 2024
d486474
Update streamlit_app.py
loonyx8 Jan 12, 2024
9b2a6fb
Update streamlit_app.py
loonyx8 Jan 12, 2024
fe2f5f2
Update streamlit_app.py
loonyx8 Jan 12, 2024
9c4767d
Update streamlit_app.py
loonyx8 Jan 12, 2024
5ed1e0a
Create main.yml
loonyx8 Jan 20, 2024
8009d42
Update streamlit_app.py
loonyx8 Jan 20, 2024
871875a
Update main.yml
loonyx8 Jan 20, 2024
190a14d
Update streamlit_app.py
loonyx8 Jan 20, 2024
cab572f
Update main.yml
loonyx8 Jan 20, 2024
a402e69
Update main.yml
loonyx8 Jan 20, 2024
c06f316
Update main.yml
loonyx8 Jan 20, 2024
f5e0a1e
Update main.yml
loonyx8 Jan 20, 2024
9c5bc50
Update main.yml
loonyx8 Jan 20, 2024
2a129c5
add quotation marks
cobaltB12 Jan 20, 2024
3831df2
added RBC count
cobaltB12 Jan 20, 2024
498e75a
Merge pull request #1 from loonyx8/quotation
loonyx8 Jan 20, 2024
3693ee9
Update streamlit_app.py
loonyx8 Jan 20, 2024
c8fe213
Update streamlit_app.py
loonyx8 Jan 20, 2024
3a4a476
add files
cobaltB12 Jan 21, 2024
7b394b7
Add files via upload
loonyx8 Jan 21, 2024
608606e
Update chatgpt_values.py
loonyx8 Jan 21, 2024
f70324f
Update streamlit_app.py
loonyx8 Jan 21, 2024
08b84f1
Update image_loading.py
loonyx8 Jan 21, 2024
11f70f3
Update image_loading.py
loonyx8 Jan 21, 2024
ca2f1b4
Update chatgpt_values.py
loonyx8 Jan 21, 2024
c5f03cc
Update main.yml
loonyx8 Jan 21, 2024
35db690
Update streamlit_app.py
loonyx8 Jan 21, 2024
cfa600a
Update image_loading.py
loonyx8 Jan 21, 2024
dd9b20f
Update image_loading.py
loonyx8 Jan 21, 2024
1d9af1b
Update image_loading.py
loonyx8 Jan 21, 2024
b6cc94e
Update streamlit_app.py
loonyx8 Jan 21, 2024
a9f7683
Update image_loading.py
loonyx8 Jan 21, 2024
594a812
Update streamlit_app.py
loonyx8 Jan 21, 2024
470fc6f
Update chatgpt_values.py
loonyx8 Jan 21, 2024
c0ff4c0
Update main.yml
loonyx8 Jan 21, 2024
7221c2d
Update chatgpt_values.py
loonyx8 Jan 21, 2024
6de526b
Update streamlit_app.py
loonyx8 Jan 21, 2024
fb18498
Update streamlit_app.py
loonyx8 Jan 21, 2024
656ba7f
Update chatgpt_values.py
loonyx8 Jan 21, 2024
24de6de
Update main.yml
loonyx8 Jan 21, 2024
d199f88
Update streamlit_app.py
loonyx8 Jan 21, 2024
8e55f6f
Update streamlit_app.py
loonyx8 Jan 21, 2024
d95726a
Update streamlit_app.py
loonyx8 Jan 21, 2024
25b2cf3
Update streamlit_app.py
loonyx8 Jan 21, 2024
b94249e
Update chatgpt_values.py
loonyx8 Jan 21, 2024
c6794b3
Update image_loading.py
loonyx8 Jan 21, 2024
cfd4a93
Update streamlit_app.py
loonyx8 Jan 21, 2024
6d86eb1
Update streamlit_app.py
loonyx8 Jan 21, 2024
b579ee1
Update image_loading.py
loonyx8 Jan 21, 2024
ff41a91
Update image_loading.py
loonyx8 Jan 21, 2024
92bdcb6
Delete .github/workflows directory
loonyx8 Jan 21, 2024
fed99b1
new anaemia and dm functions
cobaltB12 Jan 21, 2024
5f87028
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 21, 2024
06fa11f
Update chatgpt_values.py
loonyx8 Jan 21, 2024
f25c801
Update streamlit_app.py
loonyx8 Jan 21, 2024
a92997c
Update streamlit_app.py
loonyx8 Jan 21, 2024
06ce199
Update streamlit_app.py
loonyx8 Jan 21, 2024
2f999d2
Update streamlit_app.py
loonyx8 Jan 21, 2024
ef91bf9
add new calculators
cobaltB12 Jan 21, 2024
00ed091
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 21, 2024
d9e4a21
integrated to streamlit
cobaltB12 Jan 21, 2024
43bba33
change to elif
cobaltB12 Jan 21, 2024
3f8b42d
remove space
cobaltB12 Jan 21, 2024
c7006c2
remove space 2
cobaltB12 Jan 21, 2024
0a2e568
iteritems
cobaltB12 Jan 21, 2024
eeb3e10
print
cobaltB12 Jan 21, 2024
d1b8f5f
uncomment print
cobaltB12 Jan 21, 2024
2f22c17
more comment
cobaltB12 Jan 21, 2024
1dfccfe
remove useless print
cobaltB12 Jan 21, 2024
c344e95
catch output phrase
cobaltB12 Jan 21, 2024
e35682f
f
cobaltB12 Jan 21, 2024
aed77e0
gender and race lower
cobaltB12 Jan 21, 2024
9d5e8fb
ldl bp
cobaltB12 Jan 21, 2024
216a8e0
catch bp
cobaltB12 Jan 21, 2024
ee5f238
Update bmi.py
loonyx8 Jan 21, 2024
1a70534
Update lipids_ranges.py BP exception
cobaltB12 Jan 22, 2024
b80669c
Update lipids_ranges.py
cobaltB12 Jan 22, 2024
940fc10
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 22, 2024
bdd138a
minor edits to catch missing values
cobaltB12 Jan 22, 2024
e3bb050
edit phrases
cobaltB12 Jan 22, 2024
dc7b848
minor edits
cobaltB12 Jan 22, 2024
cce43f3
comment dotenv for APIkey and print outputs
cobaltB12 Jan 22, 2024
0621b49
spacing
cobaltB12 Jan 22, 2024
f7f1b46
edit return condition
cobaltB12 Jan 22, 2024
850c7e3
added testing
cobaltB12 Jan 22, 2024
67aa290
updated testing code
cobaltB12 Jan 22, 2024
46b0c75
remove mgdl
cobaltB12 Jan 24, 2024
3a14422
rephrase advice
cobaltB12 Jan 24, 2024
a683546
capitalisation
cobaltB12 Jan 24, 2024
8a1cc37
catch more exceptions
cobaltB12 Jan 25, 2024
832790a
convert cholesterol to mmol/L
loonyx8 Jan 25, 2024
fd74a89
Update streamlit_app.py
loonyx8 Jan 25, 2024
deb1da6
personal report
loonyx8 Jan 25, 2024
cd6153b
Update streamlit_app.py
loonyx8 Jan 25, 2024
f1069f4
Update streamlit_app.py
loonyx8 Jan 26, 2024
cdc0db4
update model to gpt-3.5-turbo
loonyx8 Jan 26, 2024
9fd13ed
Update chatgpt_values.py
loonyx8 Jan 26, 2024
7e581fc
Update chatgpt_values.py
loonyx8 Jan 26, 2024
fa60efe
Update image_loading.py
loonyx8 Jan 26, 2024
cd49ab2
Update chatgpt_values.py
loonyx8 Jan 26, 2024
992bdb6
Update streamlit_app.py
loonyx8 Jan 26, 2024
03487be
Update chatgpt_values.py
loonyx8 Jan 26, 2024
ca5fed4
Update chatgpt_values.py
loonyx8 Jan 26, 2024
268ffb7
Update streamlit_app.py
loonyx8 Jan 26, 2024
00bceec
Update chatgpt_values.py
loonyx8 Jan 26, 2024
e201781
catch non existent
cobaltB12 Jan 28, 2024
999f217
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 28, 2024
a03e126
quotation mark
cobaltB12 Jan 28, 2024
76ced2e
bool
cobaltB12 Jan 28, 2024
a794e09
uncomment
cobaltB12 Jan 28, 2024
7617db6
Update anaemia.py
loonyx8 Jan 28, 2024
1d64e7a
Update bmi.py
loonyx8 Jan 28, 2024
aa4527c
edit bool
cobaltB12 Jan 28, 2024
f446e6f
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 28, 2024
eb4a69f
Update diabetes.py
loonyx8 Jan 28, 2024
d550b79
Update bmi.py
loonyx8 Jan 28, 2024
216f2ad
Update lipids_ranges.py
loonyx8 Jan 28, 2024
919ba68
add logo
loonyx8 Jan 28, 2024
6fd6509
Update streamlit_app.py
loonyx8 Jan 28, 2024
bfef83d
Update diabetes.py
loonyx8 Jan 28, 2024
dc2b2c4
Update lipids_ranges.py
loonyx8 Jan 28, 2024
6dab260
Update lipids_ranges.py
loonyx8 Jan 28, 2024
047973d
Update streamlit_app.py
loonyx8 Jan 28, 2024
8b5a99b
Update lipids_ranges.py
loonyx8 Jan 28, 2024
3f9cc78
Update streamlit_app.py
loonyx8 Jan 28, 2024
2c87d96
Update streamlit_app.py
loonyx8 Jan 28, 2024
0ba5661
Update lipids_ranges.py
loonyx8 Jan 28, 2024
71ad3ae
anaemia edit
cobaltB12 Jan 30, 2024
f41b8eb
Merge branch 'master' of https://github.com/loonyx8/streamlit-example
cobaltB12 Jan 30, 2024
2abda39
uncomment
cobaltB12 Jan 30, 2024
a3ed01e
test
cobaltB12 Jan 30, 2024
f5ff9f0
end test
cobaltB12 Jan 30, 2024
759a991
Update chatgpt_values.py
loonyx8 Feb 2, 2024
9e04a8c
Update chatgpt_values.py
loonyx8 Feb 2, 2024
b45cf6c
Update chatgpt_values.py
loonyx8 Feb 2, 2024
03ef658
Update chatgpt_values.py
loonyx8 Feb 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
Binary file added __pycache__/anaemia.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/bmi.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/chatgpt_values.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/diabetes.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/image_loading.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/lipids_ranges.cpython-311.pyc
Binary file not shown.
52 changes: 52 additions & 0 deletions anaemia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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
#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"]
if hblevel < 7:
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"]:
return ":large_orange_circle: You likely 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
if not hbdict["rbc_count"]["test_found"]:
return ":large_orange_circle: You likely have anaemia, but there is not enough information to determine the cause. Visit a doctor if you have any concerns of blood loss."
mentzer = mcv/ hbdict["rbc_count"]["test_value"]
if mentzer > 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)."
else :
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 = ":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."
else:
output_phrase = ":large_green_circle: You likely do not have anaemia."
return output_phrase

#print (f"here is result: {anaemia_analysis (testdict)}")
43 changes: 43 additions & 0 deletions bmi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test_results = {
"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(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"]
if weight > 0 and height > 0:
bmi = round(weight / pow(height,2), 1)
else:
return ":large_yellow_circle: You need both weight and height to calculate BMI."
weightloss = False
if bmi >=27.5:
output_string = ":large_orange_circle: You are obese. Your BMI is " + str(bmi)
weightloss = True
elif bmi >= 23:
output_string = ":large_orange_circle: You are overweight. Your BMI is " + str(bmi)
weightloss = True
elif bmi < 18.5:
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 = ":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

#print ("advice " + bmi_advice(test_results))
123 changes: 123 additions & 0 deletions chatgpt_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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


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.

Example output json template
{
"ldl_cholesterol": {
"test_found":False,
"test_value":False,
"test_unit":False,
"test_ref_min":False,
"test_ref_max":False
},
"hdl_cholesterol": {
"test_found":True,
"test_value":False,
"test_unit":False,
"test_ref_min":False,
"test_ref_max":False
},
"total_cholesterol": {
"test_found":False,
"test_value":False,
"test_unit":False,
"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
},
"glucose":{
"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(client,extracted_text):
extract_start_time = time.time()
extract_prompt = f"{template_prompt} {extracted_text}"
response = client.chat.completions.create(
model="gpt-4-turbo-preview", #gpt-3.5-turbo-1106
seed=4022024,
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)
extract_end_time = time.time()
extract_time = int(extract_end_time - extract_start_time)
return response,test_results,extract_time
77 changes: 77 additions & 0 deletions diabetes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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
}


def get_dm_advice(inputattributes, inputdict):
print ("in dm advice")
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
if inputattributes["diabetes"]:
if a1c_value >0:
if inputattributes["age"] >= 80:
a1ctarget = 8
elif inputattributes["age"] <=40:
a1ctarget = 6.5
else:
a1ctarget = 7.0
if a1c_value > a1ctarget:
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 = ":large_green_circle: Your HbA1c is below 7, which is within expected range for a diabetic."
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:
output_phrase += " \nYour fasting glucose level is within range, <6."
else:
#diagnose dm
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 >= 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 >6.0."
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."
lifestyle = True
else:
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 += " You are highly encouraged to quit smoking."
return output_phrase

#print(f"advice {get_dm_advice(test_attributes, testdict)}")
36 changes: 36 additions & 0 deletions image_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import streamlit as st
import pandas as pd
import numpy as np
import os
import time
import base64
import json
import cv2
import re
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:
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()
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 += str(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_clean, ocr_time