Spaces:
Runtime error
Runtime error
File size: 1,531 Bytes
4f4ac90 fa7fbbd 4f4ac90 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 | from fastai.vision.all import *
import gradio as gr
from timm import *
learn = load_learner('model_extended.pkl')
# categories = 'Sunflower', 'Orchid', 'Rose'
def classify_image(img):
pred, idx, probs = learn.predict(img)
return pred
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ['sunflower.jpeg', 'orchid.jpeg', 'rose.jpeg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
# from fastai.vision.all import *
# import gradio as gr
# # Load the pre-trained model
# learn = load_learner('model.pkl')
# # Define the categories that the model can classify
# categories = ['Sunflower', 'Orchid', 'Rose']
# # Define the function to classify an image and return the predicted category label
# def classify_image(img):
# pred, idx, probs = learn.predict(img)
# return categories[idx]
# # Define the input and output types for the Gradio interface
# image_input = gr.inputs.Image(shape=(224, 224))
# label_output = gr.outputs.Label()
# # Define example images for the interface
# examples = [
# ['sunflower.jpeg'],
# ['orchid.jpeg'],
# ['rose.jpeg']
# ]
# # Create the Gradio interface
# interface = gr.Interface(
# fn=classify_image,
# inputs=image_input,
# outputs=label_output,
# examples=examples,
# title="Image Classifier",
# description="This app classifies images into three categories: Sunflower, Orchid, and Rose."
# )
# # Launch the interface
# interface.launch()
|