test-classifier / app.py
Chinat's picture
Upload app.py
8f62061
raw
history blame contribute delete
990 Bytes
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("export.pkl")
new_label = {'asian male': '老公', 'glasses asian female': '老婆'}
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="Special Detector", live=True, theme="dark-peach", description="It is a special detector...")
# 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()