Spaces:
Sleeping
Sleeping
Commit
·
cd9e010
1
Parent(s):
7586765
first working version of the gradio app
Browse files- Angry_48_48_3.png +0 -0
- Disgust_48_48_3.png +0 -0
- Fear_48_48_3.png +0 -0
- Happy_48_48_3.png +0 -0
- Neutral_48_48_3.png +0 -0
- README.md +5 -4
- Sad_48_48_3.png +0 -0
- Surprise_48_48_3.png +0 -0
- app.py +61 -0
- models/MobileNet12blocks_wdgenaug_onrawdata_valacc063.h5 +3 -0
- requirements.txt +210 -0
Angry_48_48_3.png
ADDED
|
Disgust_48_48_3.png
ADDED
|
Fear_48_48_3.png
ADDED
|
Happy_48_48_3.png
ADDED
|
Neutral_48_48_3.png
ADDED
|
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 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 |
---
|
| 2 |
+
title: Facemoods
|
| 3 |
+
emoji: 🌖
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.16.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
Sad_48_48_3.png
ADDED
|
Surprise_48_48_3.png
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
from keras.models import load_model
|
| 5 |
+
from keras.utils import load_img, img_to_array
|
| 6 |
+
from tensorflow.image import resize
|
| 7 |
+
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
#gradio interface
|
| 11 |
+
def classify_image(image):
|
| 12 |
+
input_arr = img_to_array(image)/255 #convert PIL object to numpy array and normalize
|
| 13 |
+
input_arr_resh = resize(input_arr, (48, 48)).numpy()
|
| 14 |
+
if model.channelno == 1:
|
| 15 |
+
# Model expects inputs of shape (48,48,1)
|
| 16 |
+
input_arr_resh_gray = input_arr_resh.mean(axis=2).reshape(48,48,1)
|
| 17 |
+
predictions = model.predictor.predict(np.array([input_arr_resh_gray]))
|
| 18 |
+
elif model.channelno == 3:
|
| 19 |
+
# Model expects inputs of shape (48,48,3)
|
| 20 |
+
input_arr_resh_4dims = np.expand_dims(input_arr_resh, axis=0)
|
| 21 |
+
predictions = model.predictor.predict(input_arr_resh_4dims)
|
| 22 |
+
pr_emotion = model.labeldict[predictions.argmax()]
|
| 23 |
+
prob = predictions.max()*100
|
| 24 |
+
returnstr = f'Prediction: {pr_emotion}, probability: {prob:4.1f}%'
|
| 25 |
+
predictions_f = ['%s:%5.2f'%(model.labeldict[i],p*100) for i,p in enumerate(predictions[0])]
|
| 26 |
+
print(predictions_f)
|
| 27 |
+
return returnstr
|
| 28 |
+
|
| 29 |
+
class ModelClass:
|
| 30 |
+
def __init__(self,name='EDA_CNN.h5'):
|
| 31 |
+
self.name = name
|
| 32 |
+
self.predictor = load_model(os.path.join("models",modeltouse))
|
| 33 |
+
if name == "model_mobilenet_oncleandata_valacc078.h5":
|
| 34 |
+
self.labeldict = {0: 'fear', 1: 'Angry', 2: 'Neutral', 3: 'Happy'}
|
| 35 |
+
else:
|
| 36 |
+
self.labeldict = {0: 'Angry', 1: 'Disgust', 2: 'Fear', 3: 'Happy', 4: 'Sad', 5: 'Surprise', 6: 'Neutral'}
|
| 37 |
+
if name == "EDA_CNN.h5":
|
| 38 |
+
self.channelno = 1
|
| 39 |
+
else:
|
| 40 |
+
self.channelno = 3
|
| 41 |
+
|
| 42 |
+
#modeltouse = "EDA_CNN.h5"
|
| 43 |
+
modeltouse = "MobileNet12blocks_wdgenaug_onrawdata_valacc063.h5"
|
| 44 |
+
#modeltouse = "model_mobilenet_oncleandata_valacc078.h5"
|
| 45 |
+
|
| 46 |
+
model = ModelClass(modeltouse)
|
| 47 |
+
|
| 48 |
+
image = gr.inputs.Image(shape=(48,48))
|
| 49 |
+
label = gr.outputs.Label()
|
| 50 |
+
examples = ['Happy_48_48_%d.png'%model.channelno,
|
| 51 |
+
'Neutral_48_48_%d.png'%model.channelno,
|
| 52 |
+
'Fear_48_48_%d.png'%model.channelno,
|
| 53 |
+
'Angry_48_48_%d.png'%model.channelno,
|
| 54 |
+
'Sad_48_48_%d.png'%model.channelno,
|
| 55 |
+
#'Disgust_48_48_%d.png'%model.channelno,
|
| 56 |
+
'Surprise_48_48_%d.png'%model.channelno]
|
| 57 |
+
|
| 58 |
+
# image = Image.open('./Happy_48_48_%d.png'%model.channelno)
|
| 59 |
+
# classify_image(image)
|
| 60 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 61 |
+
intf.launch(inline=False)
|
models/MobileNet12blocks_wdgenaug_onrawdata_valacc063.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
absl-py==1.4.0
|
| 2 |
+
aiohttp==3.8.3
|
| 3 |
+
aiosignal==1.3.1
|
| 4 |
+
altair==4.2.0
|
| 5 |
+
anyio==3.6.2
|
| 6 |
+
argon2-cffi==21.3.0
|
| 7 |
+
argon2-cffi-bindings==21.2.0
|
| 8 |
+
arrow==1.2.3
|
| 9 |
+
asttokens==2.2.1
|
| 10 |
+
astunparse==1.6.3
|
| 11 |
+
async-timeout==4.0.2
|
| 12 |
+
attrs==22.2.0
|
| 13 |
+
backcall==0.2.0
|
| 14 |
+
beautifulsoup4==4.11.1
|
| 15 |
+
bleach==5.0.1
|
| 16 |
+
blis==0.7.9
|
| 17 |
+
cachetools==5.2.1
|
| 18 |
+
catalogue==2.0.8
|
| 19 |
+
certifi==2022.12.7
|
| 20 |
+
cffi==1.15.1
|
| 21 |
+
charset-normalizer==2.1.1
|
| 22 |
+
click==8.1.3
|
| 23 |
+
comm==0.1.2
|
| 24 |
+
confection==0.0.4
|
| 25 |
+
contourpy==1.0.6
|
| 26 |
+
cycler==0.11.0
|
| 27 |
+
cymem==2.0.7
|
| 28 |
+
datasets==2.8.0
|
| 29 |
+
debugpy==1.6.5
|
| 30 |
+
decorator==5.1.1
|
| 31 |
+
defusedxml==0.7.1
|
| 32 |
+
dill==0.3.6
|
| 33 |
+
entrypoints==0.4
|
| 34 |
+
execnb==0.1.4
|
| 35 |
+
executing==1.2.0
|
| 36 |
+
fastai==2.7.10
|
| 37 |
+
fastapi==0.89.1
|
| 38 |
+
fastbook==0.0.29
|
| 39 |
+
fastcore==1.5.27
|
| 40 |
+
fastdownload==0.0.7
|
| 41 |
+
fastjsonschema==2.16.2
|
| 42 |
+
fastprogress==1.0.3
|
| 43 |
+
ffmpy==0.3.0
|
| 44 |
+
filelock==3.9.0
|
| 45 |
+
flatbuffers==23.1.4
|
| 46 |
+
fonttools==4.38.0
|
| 47 |
+
fqdn==1.5.1
|
| 48 |
+
frozenlist==1.3.3
|
| 49 |
+
fsspec==2022.11.0
|
| 50 |
+
gast==0.4.0
|
| 51 |
+
ghapi==1.0.3
|
| 52 |
+
google-auth==2.16.0
|
| 53 |
+
google-auth-oauthlib==0.4.6
|
| 54 |
+
google-pasta==0.2.0
|
| 55 |
+
gradio==3.16.1
|
| 56 |
+
graphviz==0.20.1
|
| 57 |
+
grpcio==1.51.1
|
| 58 |
+
h11==0.14.0
|
| 59 |
+
h5py==3.7.0
|
| 60 |
+
httpcore==0.16.3
|
| 61 |
+
httpx==0.23.3
|
| 62 |
+
huggingface-hub==0.11.1
|
| 63 |
+
idna==3.4
|
| 64 |
+
importlib-metadata==6.0.0
|
| 65 |
+
ipykernel==6.20.1
|
| 66 |
+
ipython==8.8.0
|
| 67 |
+
ipython-genutils==0.2.0
|
| 68 |
+
ipywidgets==7.7.2
|
| 69 |
+
isoduration==20.11.0
|
| 70 |
+
jedi==0.18.2
|
| 71 |
+
Jinja2==3.1.2
|
| 72 |
+
joblib==1.2.0
|
| 73 |
+
jsonpointer==2.3
|
| 74 |
+
jsonschema==4.17.3
|
| 75 |
+
jupyter-contrib-core==0.4.2
|
| 76 |
+
jupyter-contrib-nbextensions==0.7.0
|
| 77 |
+
jupyter-events==0.6.2
|
| 78 |
+
jupyter-highlight-selected-word==0.2.0
|
| 79 |
+
jupyter-nbextensions-configurator==0.6.1
|
| 80 |
+
jupyter_client==7.4.8
|
| 81 |
+
jupyter_core==5.1.3
|
| 82 |
+
jupyter_server==2.0.6
|
| 83 |
+
jupyter_server_terminals==0.4.4
|
| 84 |
+
jupyterlab-pygments==0.2.2
|
| 85 |
+
jupyterlab-widgets==1.1.1
|
| 86 |
+
keras==2.11.0
|
| 87 |
+
kiwisolver==1.4.4
|
| 88 |
+
langcodes==3.3.0
|
| 89 |
+
libclang==15.0.6.1
|
| 90 |
+
linkify-it-py==1.0.3
|
| 91 |
+
lxml==4.9.2
|
| 92 |
+
Markdown==3.4.1
|
| 93 |
+
markdown-it-py==2.1.0
|
| 94 |
+
MarkupSafe==2.1.1
|
| 95 |
+
matplotlib==3.6.3
|
| 96 |
+
matplotlib-inline==0.1.6
|
| 97 |
+
mdit-py-plugins==0.3.3
|
| 98 |
+
mdurl==0.1.2
|
| 99 |
+
mistune==2.0.4
|
| 100 |
+
multidict==6.0.4
|
| 101 |
+
multiprocess==0.70.14
|
| 102 |
+
murmurhash==1.0.9
|
| 103 |
+
nbclassic==0.4.8
|
| 104 |
+
nbclient==0.7.2
|
| 105 |
+
nbconvert==7.2.7
|
| 106 |
+
nbdev==2.3.9
|
| 107 |
+
nbformat==5.7.3
|
| 108 |
+
nest-asyncio==1.5.6
|
| 109 |
+
notebook==6.5.2
|
| 110 |
+
notebook_shim==0.2.2
|
| 111 |
+
numpy==1.24.1
|
| 112 |
+
nvidia-cublas-cu11==11.10.3.66
|
| 113 |
+
nvidia-cuda-nvrtc-cu11==11.7.99
|
| 114 |
+
nvidia-cuda-runtime-cu11==11.7.99
|
| 115 |
+
nvidia-cudnn-cu11==8.5.0.96
|
| 116 |
+
oauthlib==3.2.2
|
| 117 |
+
opt-einsum==3.3.0
|
| 118 |
+
orjson==3.8.5
|
| 119 |
+
packaging==23.0
|
| 120 |
+
pandas==1.5.2
|
| 121 |
+
pandocfilters==1.5.0
|
| 122 |
+
parso==0.8.3
|
| 123 |
+
pathy==0.10.1
|
| 124 |
+
pexpect==4.8.0
|
| 125 |
+
pickleshare==0.7.5
|
| 126 |
+
Pillow==9.4.0
|
| 127 |
+
platformdirs==2.6.2
|
| 128 |
+
preshed==3.0.8
|
| 129 |
+
prometheus-client==0.15.0
|
| 130 |
+
prompt-toolkit==3.0.36
|
| 131 |
+
protobuf==3.19.6
|
| 132 |
+
psutil==5.9.4
|
| 133 |
+
ptyprocess==0.7.0
|
| 134 |
+
pure-eval==0.2.2
|
| 135 |
+
pyarrow==10.0.1
|
| 136 |
+
pyasn1==0.4.8
|
| 137 |
+
pyasn1-modules==0.2.8
|
| 138 |
+
pycparser==2.21
|
| 139 |
+
pycryptodome==3.16.0
|
| 140 |
+
pydantic==1.10.4
|
| 141 |
+
pydub==0.25.1
|
| 142 |
+
Pygments==2.14.0
|
| 143 |
+
pyparsing==3.0.9
|
| 144 |
+
pyrsistent==0.19.3
|
| 145 |
+
python-dateutil==2.8.2
|
| 146 |
+
python-json-logger==2.0.4
|
| 147 |
+
python-multipart==0.0.5
|
| 148 |
+
pytz==2022.7
|
| 149 |
+
PyYAML==6.0
|
| 150 |
+
pyzmq==25.0.0
|
| 151 |
+
regex==2022.10.31
|
| 152 |
+
requests==2.28.1
|
| 153 |
+
requests-oauthlib==1.3.1
|
| 154 |
+
responses==0.18.0
|
| 155 |
+
rfc3339-validator==0.1.4
|
| 156 |
+
rfc3986==1.5.0
|
| 157 |
+
rfc3986-validator==0.1.1
|
| 158 |
+
rsa==4.9
|
| 159 |
+
scikit-learn==1.2.0
|
| 160 |
+
scipy==1.10.0
|
| 161 |
+
Send2Trash==1.8.0
|
| 162 |
+
sentencepiece==0.1.97
|
| 163 |
+
six==1.16.0
|
| 164 |
+
smart-open==6.3.0
|
| 165 |
+
sniffio==1.3.0
|
| 166 |
+
soupsieve==2.3.2.post1
|
| 167 |
+
spacy==3.4.4
|
| 168 |
+
spacy-legacy==3.0.11
|
| 169 |
+
spacy-loggers==1.0.4
|
| 170 |
+
srsly==2.4.5
|
| 171 |
+
stack-data==0.6.2
|
| 172 |
+
starlette==0.22.0
|
| 173 |
+
tensorboard==2.11.2
|
| 174 |
+
tensorboard-data-server==0.6.1
|
| 175 |
+
tensorboard-plugin-wit==1.8.1
|
| 176 |
+
tensorflow==2.11.0
|
| 177 |
+
tensorflow-estimator==2.11.0
|
| 178 |
+
tensorflow-io-gcs-filesystem==0.29.0
|
| 179 |
+
termcolor==2.2.0
|
| 180 |
+
terminado==0.17.1
|
| 181 |
+
thinc==8.1.6
|
| 182 |
+
threadpoolctl==3.1.0
|
| 183 |
+
tinycss2==1.2.1
|
| 184 |
+
tokenizers==0.13.2
|
| 185 |
+
toolz==0.12.0
|
| 186 |
+
torch==1.13.1
|
| 187 |
+
torchvision==0.14.1
|
| 188 |
+
tornado==6.2
|
| 189 |
+
tqdm==4.64.1
|
| 190 |
+
traitlets==5.8.1
|
| 191 |
+
transformers==4.25.1
|
| 192 |
+
typer==0.7.0
|
| 193 |
+
typing_extensions==4.4.0
|
| 194 |
+
uc-micro-py==1.0.1
|
| 195 |
+
uri-template==1.2.0
|
| 196 |
+
urllib3==1.26.14
|
| 197 |
+
uvicorn==0.20.0
|
| 198 |
+
wasabi==0.10.1
|
| 199 |
+
watchdog==2.2.1
|
| 200 |
+
wcwidth==0.2.5
|
| 201 |
+
webcolors==1.12
|
| 202 |
+
webencodings==0.5.1
|
| 203 |
+
websocket-client==1.4.2
|
| 204 |
+
websockets==10.4
|
| 205 |
+
Werkzeug==2.2.2
|
| 206 |
+
widgetsnbextension==3.6.1
|
| 207 |
+
wrapt==1.14.1
|
| 208 |
+
xxhash==3.2.0
|
| 209 |
+
yarl==1.8.2
|
| 210 |
+
zipp==3.11.0
|