AyoAgbaje commited on
Commit
7293c0c
·
verified ·
1 Parent(s): 1003dd8

Upload 3 files

Browse files

All 3 files required to kick-start with the app: The model, the requirements file and the app itself

Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +44 -0
  3. efficientnet_b0.keras +3 -0
  4. requirements.txt +5 -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_b0.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ import keras
6
+ import keras_cv
7
+ from keras.models import load_model
8
+ import cv2
9
+
10
+
11
+ def image_predict(img_):
12
+ model = load_model('efficientnet_b0.keras')
13
+ img = cv2.cvtColor(img_, cv2.COLOR_BGR2RGB)
14
+ img = cv2.resize(img, dsize = [224, 224])
15
+ img = img / 255.0
16
+ img = np.expand_dims(img, axis = 0)
17
+
18
+ pred = model.predict(img, verbose = 1)
19
+ pred = np.argmax(pred, axis = 1)
20
+
21
+ classes = ['angry', 'happy', 'neutral', 'sad', 'suprised', 'tired']
22
+ if pred == 0:
23
+ answer = f"Facial Expression detected is: {classes[0].capitalize()}"
24
+ elif pred == 1:
25
+ answer = f"Facial Expression detected is: {classes[1].capitalize()}"
26
+ elif pred == 2:
27
+ answer = f"Facial Expression detected is: {classes[2].capitalize()}"
28
+ elif pred == 3:
29
+ answer = f"Facial Expression detected is: {classes[3].capitalize()}"
30
+ elif pred == 4:
31
+ answer = f"Facial Expression detected is: {classes[4].capitalize()}"
32
+ elif pred == 5:
33
+ answer = f"Facial Expression detected is: {classes[5].capitalize()}"
34
+
35
+ return answer
36
+
37
+
38
+ with gr.Blocks() as demo:
39
+ image_ = gr.Image(label = 'Input Image to be predicted')
40
+ output = gr.Textbox(label = 'Prediction')
41
+ btn = gr.Button('Predict')
42
+ btn.click(fn = image_predict, inputs = [image_], outputs = output)
43
+
44
+ demo.launch(share = False)
efficientnet_b0.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98c910ebdc0f8599265f2134445f6da9e744498529ec7473cd695d593a6d1d47
3
+ size 118532155
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ keras==3.3.3
2
+ opencv-python==4.9.0.80
3
+ tensorflow==2.15.0
4
+ numpy==1.24.4
5
+ gradio==