mauricioplopes's picture
Update app.py
717057c
raw
history blame contribute delete
932 Bytes
__all__ = ['facemark', 'learn', 'classify_image', 'categories', 'image', 'labels', 'into']
from fastai.vision.all import *
from huggingface_hub import from_pretrained_fastai
import gradio as gr
learn = from_pretrained_fastai('mauricioplopes/facemask-model')
categories = ('WithMask', 'WithoutMask')
# Function to classify an image
def classify_image(image_path):
# Open and display the image
img = PILImage.create(image_path)
img.show()
# Make predictions on the image
pred, class_idx, proba = learn.predict(img)
class_idx = class_idx.item()
# Get the predicted class label and confidence score
result = {'WithMask': proba[0].numpy().tolist(), 'WithoutMask': proba[1].numpy().tolist()}
return result
image = gr.inputs.Image(shape = (192, 192))
label = gr.outputs.Label()
into = gr.Interface(fn = classify_image, inputs = image, outputs = label)
into.launch(inline = False, share = True)