wgpubs's picture
ux
f8ce11f
from fastai.vision.all import *
from fastcore.all import *
import gradio as gr
data_path = Path("./data")
models_path = Path("./models")
examples_path = Path("./nbs/examples")
# code required for serving predictions
def is_marvel(img):
return 1.0 if img.parent.name.lower().startswith("marvel") else 0.0
inf_learn = load_learner(models_path / "export.pkl")
def predict(img):
pred, _, _ = inf_learn.predict(img)
return f"{pred[0]*100:.2f}%"
# define our Gradio Interface instance and launch it
with open("gradio_article.md") as f:
article = f.read()
interface_config = {
"title": "🦸🦸‍♀️ Is it a Marvel Character? 🦹🦹‍♀️",
"description": "For those wanting to make sure they are rooting on the right heroes. Based on Jeremy Howards ['Is it a bird? Creating a model from your own data'](https://www.kaggle.com/code/jhoward/is-it-a-bird-creating-a-model-from-your-own-data)",
"article": article,
"examples": [f"{examples_path}/{f.name}" for f in examples_path.iterdir()],
"interpretation": None,
"layout": "horizontal",
"allow_flagging": "never",
}
demo = gr.Interface(
fn=predict,
inputs=gr.inputs.Image(shape=(512, 512)),
outputs=gr.outputs.Textbox(label="Marvel character probability"),
**interface_config,
)
demo.launch()