File size: 1,100 Bytes
a72431b a3c0682 a72431b d71299d a72431b 575318e a72431b c4527cf a72431b c4527cf aea983c 575318e c4527cf |
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 |
# %% ../hugging-space-model-app.ipynb 4
from fastai.vision.all import *
import gradio as gr
# %% ../hugging-space-model-app.ipynb 7
learn = load_learner('facial_exp_model.pkl')
# %% ../hugging-space-model-app.ipynb 9
labels = learn.dls.vocab
def classify_image(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
examples = ['afraid.jpg','anger.jpg','happyface.jpg','disgust.jpg','sadface.webp','neutral.webp']
# %% ../hugging-space-model-app.ipynb 11
with gr.Blocks(theme=gr.themes.Soft())as demo:
gr.HTML("<center><h1>EmoPix - Facial Expressions Classifier! ππ</h1><center>")
gr.Markdown("""##### Classifies human facial expressions from an uploaded image.
<b>Upload images and have funπ€. Classifies facial expressions with 75% accuracy</b>""")
gr.Interface(fn=classify_image,
inputs=gr.components.Image(),
outputs=gr.components.Label(show_label=True,num_top_classes=3),
examples=examples)
demo.launch(inline=False) |