bonosa
yay!
7769d7f
import torch
import sys
import pathlib
import os
from pathlib import Path
from fastai.vision.all import load_learner, PILImage
import gradio
from gradio import Interface, Image, Label
def custom_resnet_splitter(model):
resnet = model[0]
return [params(resnet[0]), params(resnet[1]), params(resnet[4]), params(resnet[5]), params(resnet[6]), params(resnet[7]), params(model[1])]
def predict_parrot_species(image):
model_path = os.path.abspath('parrotclasscolab.pkl') # Resolve the path object
learn_inf = load_learner(str(model_path)) # Convert the Path object to a string
pred, _, _ = learn_inf.predict(image)
return pred
input_image = Image(shape=(224, 224))
output_label = Label()
# Add a list of sample image URLs
example_images = [
"caique.jpg",
"grey.jpg",
"macaw.jpg",
"cockatiel.jpg"
]
description_text = "Example images for this app:"
gr_interface = gradio.Interface(
fn=predict_parrot_species,
inputs=input_image,
outputs=output_label,
description=description_text,
examples=example_images
)
gr_interface.launch()