pet_identifier / app.py
Girishug's picture
Update app.py
1ae1689 verified
Raw
History Blame Contribute Delete
876 Bytes
import gradio as gr
from fastai.vision.all import load_learner, PILImage
# Load the exported model
learn = load_learner('exported_model.pkl')
# Define prediction function
def predict_image(image):
img = PILImage.create(image)
pred, _, probs = learn.predict(img)
return {str(pred): float(probs.max())}
# Instructions
instructions = """
**Instructions:**
1. Upload an image of your pet.
2. Click the "Submit" button to identify the breed.
3. The result will appear on the right side.
4. Use the "Clear" button to reset the input and output fields.
"""
# Create Gradio interface
interface = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="Pet Identifier",
description=instructions,
allow_flagging="never"
)
# Launch the interface
if __name__ == "__main__":
interface.launch()