SmileOrFrown / app.py
Jonathon Cwik
add timm
4b1db9b
raw
history blame contribute delete
646 Bytes
import gradio as gr
from nbconvert import export
import numpy as np
from fastai.vision.all import *
import pathlib
import timm
plt = platform.system()
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
learner = load_learner("model.pkl")
categories = ('happy', 'upset')
def smileOrFrown(im):
pred,idx,probs = learner.predict(im)
actualPred = "happy"
if (pred == "human face upset"):
actualPred = "upset"
return actualPred + " " + str(dict(zip(categories, map(float, probs))))
demo = gr.Interface(
smileOrFrown,
gr.Image(source="webcam", streaming=True),
"text",
live=True
)
demo.launch()