firstmodel / app.py
eng-himanshu's picture
Update app.py
8a995a0 verified
raw
history blame
649 Bytes
from fastai.vision.all import *
import gradio as gr
# Load the model and define categories
categories = ['dog', 'cat']
learn = load_learner('model.pkl')
def is_cat(img):
pred, idx, probs = learn.predict(img)
return {categories[i]: float(probs[i]) for i in range(len(categories))}
# Create Gradio interface components
image = gr.components.Image()
label = gr.components.Label()
examples = [['dog.jpg'], ['cat.jpg']]
# Create and launch the interface
interface = gr.Interface(
fn=is_cat,
inputs=image,
outputs=label,
examples=examples,
title="Cat vs Dog Classifier"
)
if __name__ == "__main__":
interface.launch()