Spaces:
Runtime error
Runtime error
File size: 1,088 Bytes
3858d46 814099f 95fb4df 1e8d856 f1bcd11 7ee88d3 95fb4df 1e8d856 26e94d3 f1bcd11 1e8d856 f9212bb a506ff4 3858d46 6db3fcd 7769d7f |
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 |
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() |