File size: 2,039 Bytes
3ef37b3
e6fbb1f
 
 
 
 
 
e29dc20
e6fbb1f
 
e29dc20
e6fbb1f
 
 
 
 
438060c
e6fbb1f
 
 
 
 
 
 
 
 
438060c
e6fbb1f
d6f38b9
e6fbb1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96824c3
 
 
e6fbb1f
 
 
 
 
 
 
96824c3
 
 
 
9e34198
 
 
e6fbb1f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
from utils import *
import torch
import pickle
from PIL import Image

resnetmodel = custom_resnet()
resnetmodel.load_state_dict(torch.load('/app/MIN_RESNET101_BMI_Cache_test.pkl', map_location=torch.device('cpu')))
resnetmodel = resnetmodel.to(device)
resnetmodel.eval()
gpr = pickle.load(open('/app/gpr_model_withgender.pkl', 'rb'))
obj = Data_Processor()


def get_features(img):
    values = []
    image = Image.open(img).convert('RGB')
    values.append(1)
    body_feature = obj.test(image)
    values.append(body_feature.WSR)
    values.append(body_feature.WTR)
    values.append(body_feature.WHpR)
    values.append(body_feature.WHdR)
    values.append(body_feature.HpHdR)
    values.append(body_feature.Area)
    values.append(body_feature.H2W)
    image = Image.open(img).convert('RGB')
    image = ScaleAndPadTransform(224).transform(image)
    image = image.unsqueeze(0)
    data = image.to("cpu")
    conv_out = LayerActivations(resnetmodel.fc1, 1)
    out = resnetmodel(data)
    conv_out.remove()
    xs = torch.squeeze(conv_out.features.cpu().detach()).numpy()

    for x in xs:
        values.append(float(x))

    return values
def main():
    st.title("BMI Prediction App")

    image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
    if image is not None:
        cols = st.columns(2)  # Create two columns
        with cols[0]:  # Place image in the first column
            st.image(image, caption="Uploaded Image", use_column_width=True)
        
        # Convert image to features
        values = get_features(image)
        
        # Predict BMI using Gaussian Process Regression
        bmi_pred = gpr.predict([values])
        
        with cols[1]:  # Place prediction in the second column
            st.write("Predicted BMI:", bmi_pred[0])
            st.success("Prediction Completed")
        
        st.balloons()
        st.write("<script>window.scrollTo(0, document.body.scrollHeight);</script>", unsafe_allow_html=True)

if __name__ == "__main__":
    main()