mask_detection / app.py
Chinat's picture
Update app.py
6d2d581
import gradio as gr
from fastai import *
from fastai.vision.all import *
import pathlib
plt = platform.system()
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
learn_inf = load_learner("mask_detection_model.pkl")
new_label = {'white face mask': 'Student wearing mask', 'human face': 'Report! Student without mask detected'}
def predict_person(img):
pred, pred_idx, probs = learn_inf.predict(img)
return f'Prediction: {new_label[pred]}; Probability: {probs[pred_idx]:.04f}'
gr.inputs.Image(tool=False, optional=False)
webpage = gr.Interface(fn=predict_person, inputs=gr.inputs.Image(tool=False, optional=False), outputs="text", title="Face Mask Detector", live=True, theme="dark-peach", description="Check if a student is wearing a mask")
# webpage = gr.Interface(fn=predict_person, inputs=gr.inputs.Image(tool=False, optional=False), outputs="text", title="Special Detector", live=True, theme="dark-peach", description="It is a special detector...", examples=[["example1.jpg"], ["example2.jpg"], ["example3.jpg"]])
webpage.launch()