levi15 commited on
Commit
6c50e42
1 Parent(s): cd4ee57

Upload 6 files

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. EfficientNet_ModelWeights.keras +3 -0
  3. README.md +2 -12
  4. app.py +110 -0
  5. index.html +21 -0
  6. requirements.txt +9 -0
  7. styles.css +40 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ EfficientNet_ModelWeights.keras filter=lfs diff=lfs merge=lfs -text
EfficientNet_ModelWeights.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0751c1be6cda630868a74d1c0409694fc2e638fd3af2d519de7f6220469f2b12
3
+ size 18180480
README.md CHANGED
@@ -1,12 +1,2 @@
1
- ---
2
- title: Face Expresion15
3
- emoji: 👁
4
- colorFrom: pink
5
- colorTo: pink
6
- sdk: streamlit
7
- sdk_version: 1.32.2
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # Expresso
2
+ I have built a model which tries to predict the facial expression of the image provided. This model is using the EfficientNet as its base model. The current idea works only for a limited number of expressions.
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # from flask import Flask, request, jsonify, render_template
2
+ # from tensorflow.keras.models import load_model
3
+ # from tensorflow.keras.preprocessing import image
4
+ # from efficientnet.tfkeras import preprocess_input
5
+ # import numpy as np
6
+
7
+ # app = Flask(__name__)
8
+
9
+ # model = load_model('EfficientNet_ModelWeights.keras')
10
+
11
+ # def preprocess_and_predict(model, img_path, target_size=(224, 224)):
12
+ # # Load and preprocess the image
13
+ # img = image.load_img(img_path, target_size=target_size)
14
+ # img_array = image.img_to_array(img)
15
+ # img_array = np.expand_dims(img_array, axis=0)
16
+ # img_array = preprocess_input(img_array)
17
+
18
+ # # Make prediction
19
+ # prediction = model.predict(img_array)
20
+ # predicted_class = np.argmax(prediction)
21
+
22
+ # # Return the predicted class
23
+ # return predicted_class
24
+
25
+ # @app.route('/')
26
+ # def home():
27
+ # return render_template('index.html')
28
+
29
+ # @app.route('/predict', methods=['POST'])
30
+ # def predict():
31
+ # if 'file' not in request.files:
32
+ # return jsonify({'error': 'No file part'})
33
+
34
+ # file = request.files['file']
35
+
36
+ # # Save the uploaded file temporarily
37
+ # file_path = 'temp_image.jpg'
38
+ # file.save(file_path)
39
+
40
+ # # Make prediction
41
+ # predicted_class = preprocess_and_predict(model, file_path)
42
+
43
+ # # Return the predicted class as a response
44
+ # return render_template('index.html', prediction=predicted_class)
45
+
46
+ # if __name__ == '__main__':
47
+ # app.run(debug=True)
48
+
49
+ import streamlit as st
50
+ from tensorflow.keras.models import load_model
51
+ from tensorflow.keras.preprocessing import image
52
+ from efficientnet.tfkeras import preprocess_input
53
+ import numpy as np
54
+
55
+ # Load your machine learning model
56
+ @st.cache(allow_output_mutation=True)
57
+ def load_model():
58
+ return load_model('EfficientNet_ModelWeights.keras')
59
+
60
+ # Prediction function
61
+ def preprocess_and_predict(model, img_path, target_size=(224, 224)):
62
+ # Load and preprocess the image
63
+ img = image.load_img(img_path, target_size=target_size)
64
+ if img is None:
65
+ print("Error: Image not loaded.")
66
+ return None
67
+
68
+ # Converting image to array and preprocessing using EfficientNet's preprocessing
69
+ img_array = image.img_to_array(img)
70
+ img_array = np.expand_dims(img_array, axis=0)
71
+ img_array = preprocess_input(img_array)
72
+
73
+ # Predicting the class label
74
+ preds = model.predict(img_array)
75
+ predicted_label = np.argmax(preds[0])
76
+
77
+ reverse_expression_labels = {v: k for k, v in expression_labels.items()}
78
+
79
+ # Converting the predicted label index to its corresponding expression label
80
+ predicted_expression_label = reverse_expression_labels[predicted_label]
81
+
82
+ return predicted_expression_label
83
+ def main():
84
+ st.title('Expresso - Image Prediction')
85
+
86
+ # Display the custom HTML content
87
+ with open("index.html", "r", encoding="utf-8") as file:
88
+ html_code = file.read()
89
+ st.components.v1.html(html_code, width=700, height=800)
90
+
91
+ # Load the model
92
+ model = load_model()
93
+
94
+ # Check if the file uploader is used
95
+ if st.file_uploader is not None:
96
+ uploaded_file = st.file_uploader("Upload your image", type=['jpg', 'png'])
97
+ if uploaded_file is not None:
98
+ # Make prediction when the "Predict" button is clicked
99
+ if st.button('Predict'):
100
+ # Save the uploaded file temporarily
101
+ with open("temp_image.jpg", "wb") as f:
102
+ f.write(uploaded_file.read())
103
+ # Make prediction
104
+ predicted_class = preprocess_and_predict(model, "temp_image.jpg")
105
+ # Display prediction result
106
+ st.write(f'Predicted Class: {predicted_class}')
107
+
108
+ if __name__ == '__main__':
109
+ main()
110
+
index.html ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Expresso - Image Prediction</title>
7
+ <link rel="stylesheet" href="styles.css">
8
+ </head>
9
+ <body>
10
+
11
+ <div class="container">
12
+ <h1>Expresso - Image Prediction</h1>
13
+ <form id="uploadForm" enctype="multipart/form-data" action="/predict" method="post">
14
+ <label for="imageUpload" style="display: block; text-align: center; margin-bottom: 20px;">Upload your image</label>
15
+ <input type="file" id="imageUpload" name="file" style="display: block; margin: 0 auto 20px;" accept="image/*">
16
+ <button type="submit" class="upload-btn">Predict</button>
17
+ </form>
18
+ </div>
19
+
20
+ </body>
21
+ </html>
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pandas==1.3.0
2
+ numpy==1.19.5
3
+ scikit-learn==1.0.1
4
+ matplotlib==3.5.0
5
+ matplotlib-inline==0.1.3
6
+ seaborn==0.11.1
7
+ tensorflow==2.6.0
8
+ tensorboard==2.6.0
9
+ streamlit==1.2.0
styles.css ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, sans-serif;
3
+ margin: 0;
4
+ padding: 20px;
5
+ background-image: url('https://img.freepik.com/free-vector/emoticons-with-empty-space-background_79603-1023.jpg');
6
+ background-size: cover;
7
+ background-position: center;
8
+ display: flex;
9
+ justify-content: center;
10
+ align-items: center;
11
+ height: 100vh;
12
+ }
13
+
14
+ .container {
15
+ max-width: 600px;
16
+ background-color: rgba(255, 255, 255, 0.8);
17
+ padding: 20px;
18
+ border-radius: 10px;
19
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
20
+ }
21
+
22
+ h1 {
23
+ text-align: center;
24
+ }
25
+
26
+ .upload-btn {
27
+ display: block;
28
+ margin: 20px auto;
29
+ padding: 10px 20px;
30
+ background-color: #007bff; /* Blue button */
31
+ color: #fff; /* White text */
32
+ border: none;
33
+ border-radius: 5px;
34
+ cursor: pointer;
35
+ transition: background-color 0.3s;
36
+ }
37
+
38
+ .upload-btn:hover {
39
+ background-color: #0056b3; /* Darker blue on hover */
40
+ }