Spaces:
Runtime error
Runtime error
File size: 1,316 Bytes
4ad6955 f8ce11f 4ad6955 |
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 40 41 42 43 44 |
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()
|