naman1011 commited on
Commit
8fa6a1e
Β·
1 Parent(s): 6d2ec5c

first commit

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: BMIPredictor
3
- emoji: 🌍
4
  colorFrom: yellow
5
- colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.19.0
8
  app_file: app.py
 
1
  ---
2
+ title: BMIAPP
3
+ emoji: πŸ“Š
4
  colorFrom: yellow
5
+ colorTo: gray
6
  sdk: streamlit
7
  sdk_version: 1.19.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import streamlit as st
3
+ from keras_vggface.vggface import VGGFace
4
+ import tensorflow as tf
5
+ from tensorflow.keras.applications import ResNet50
6
+ from tensorflow.keras.preprocessing import image
7
+ from tensorflow.keras.models import Model
8
+ from tensorflow.keras.layers import GlobalAveragePooling2D
9
+ import numpy as np
10
+ import pickle
11
+
12
+ pickle_file_path = 'models/svm_model.pkl'
13
+
14
+ with open(pickle_file_path, 'rb') as file:
15
+ svm_model = pickle.load(file)
16
+
17
+ base_model = VGGFace(model='vgg16', include_top=False, input_shape=(224, 224, 3))
18
+ x = base_model.output
19
+ x = GlobalAveragePooling2D()(x)
20
+ model = Model(inputs=base_model.input, outputs=x)
21
+
22
+ # Function to preprocess the image
23
+ def preprocess_image(img):
24
+ img = cv2.resize(img, (224, 224))
25
+ img = image.img_to_array(img)
26
+ img = np.expand_dims(img, axis=0)
27
+ img = img[0] # Remove the extra dimension
28
+ return img
29
+
30
+ def extract_features(image_array):
31
+ # img = np.squeeze(image_array, axis=0)
32
+ img = np.expand_dims(image_array, axis=0)
33
+ img = tf.keras.applications.resnet50.preprocess_input(img)
34
+ features = model.predict(img,verbose=0)
35
+ return features.flatten()
36
+
37
+ # Function to predict BMI
38
+ def predict_bmi(img):
39
+ pre_img = preprocess_image(img)
40
+ features = extract_features(pre_img)
41
+ features = features.reshape(1,-1)
42
+ pred = svm_model.predict(features)
43
+ return pred
44
+
45
+ def main():
46
+ st.title("BMI Prediction from Camera Image")
47
+ st.write("This app predicts the BMI of a person from an image captured using the camera.")
48
+
49
+ # Capture an image from the camera using streamlit-media's camera_input function
50
+ img_file_buffer = st.camera_input("Take a picture")
51
+
52
+ if img_file_buffer is not None:
53
+ # Load the image data from the file buffer
54
+ file_bytes = np.asarray(bytearray(img_file_buffer.getvalue()), dtype=np.uint8)
55
+ img = cv2.imdecode(file_bytes, 1)
56
+
57
+ # Preprocess the image and predict BMI
58
+ bmi_label = predict_bmi(img)
59
+
60
+ # Display the predicted BMI
61
+ st.write("Predicted BMI:", str(bmi_label[0] - 5))
62
+
63
+ if __name__ == '__main__':
64
+ main()
haarcascade_frontalface_default.xml ADDED
The diff for this file is too large to render. See raw diff
 
models/.DS_Store ADDED
Binary file (6.15 kB). View file
 
models/svm_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc60072fd9b695c90d2b687ae9952b5d9c87c78d0c8f1e47373b552b5605a7bd
3
+ size 12949427
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python3-opencv
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ tensorflow==2.10.0
2
+ opencv-python
3
+ streamlit==1.22.0
4
+ keras_applications
5
+ keras_vggface @ git+https://github.com/rcmalli/keras-vggface.git
6
+ numpy==1.23.5
7
+ streamlit-webrtc
8
+ scikit-learn