Spaces:
Sleeping
Sleeping
File size: 1,167 Bytes
92b42f4 6d77a6c 92b42f4 6d77a6c ced6706 a3a8a41 ced6706 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from huggingface_hub import from_pretrained_fastai
import gradio as gr
learn = from_pretrained_fastai('./deadpool-detection-model.pkl')
labels = learn.dls.vocab
def predict(img):
yes_reaction = "reactions/yes.jfif"
no_reaction = "reactions/no.jfif"
what_reaction = "reactions/what.jpg"
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
index = pred_idx.item()
probability = probs[index].item()
isDeadpool = pred == "Deadpool"
if isDeadpool:
x = "is"
else:
x = "is not"
print("The probability is: [" + str(probability) + "] that this " + x + " Deadpool")
if probability < .75:
return PILImage.create(what_reaction)
elif isDeadpool:
return PILImage.create(yes_reaction)
else:
return PILImage.create(no_reaction)
demo = gr.Interface(
title="Deadpool™️ Detector",
fn=predict,
inputs=gr.Image(shape=(200,200)),
outputs=gr.Image(shape=(200,200)),
examples=["examples/deadpool_example1.jpg", "examples/deadpool_example2.jpg", "examples/deadpool_example3.jpg", "examples/spiderman.jpg",]
).launch(share=true) |