arham061's picture
Update app.py
cfcd37d
raw
history blame
824 Bytes
from fastai.vision.all import *
import gradio as gr
import cv2
__all__ = ['is_rock', 'learn', 'classify_images', 'get_webcam_image' 'categories', 'image', 'label', 'examples', 'intf']
def is_rock(x): return x[0].issuper()
learn = load_learner('RPS_model2.pkl')
categories = ('paper', 'rock', 'scissors')
def classify_images(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
def get_webcam_image():
cap = cv2.VideoCapture(0)
_, frame = cap.read()
cap.release()
return frame
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['rock.jpg', 'paper.jpg', 'scissor.jpg']
intf = gr.Interface(fn = classify_images, inputs = image, outputs = label, examples = examples, capture=True, capture_fn=get_webcam_image)
intf.launch()